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!
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];