Generics (Exercise) – Learn C#

0  comments

Generics are an amazing feature of C# and many other languages. They enable us to write code once and use it with many different types. What does that mean? Well, let’s find out!

This is an exercise for this YouTube video.

Happy learning and good luck!

 

[qsm quiz=11]

Assignment: Create a method which will reverse the order of any array.

 

 

Click to see the answer
static T[] ReverseArray(T[] array)
{
    T[] reversedArray = new T[array.Length];
    for (int i = array.Length - 1; i >= 0; i--)
        reversedArray[array.Length - 1 - i] = array[i];
    return reversedArray;
}

 

 

 

About the author 

Matt Rešetár

Matt is an app developer with a knack for teaching others. Working as a freelancer and most importantly developer educator, he is set on helping other people succeed in their Flutter app development career.

You may also like

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>