What is the general alternative to array?

In C #, some collections, such as ArrayListand HashTable, have common alternatives, which are List<T>and Dictionary<TKey, TValue>.

Does Array also have a common alternative?

+3
source share
5 answers

If you are looking for the general type of collection closest to the array, then you will probably need it List<T>. But this is not the same.

, : , , . . T[].

, :

void SomeFunction(int[] x) 

:

void SomeFunction<T>(T[] x) 

int :

SomeFunction<int>(myIntArray)
+4

- , . int[]. " " Array - , , . Array , .

+6

Array , .

. System.Array , int [] .

+4

, .

public static T[] CreateArray<T>(T item1, T item2) {
   T[] array = new T[2];
   array[0] = item1;
   array[1] = item2;
   return array;
}
+1

, . - . Aray - .

0

Source: https://habr.com/ru/post/1703760/


All Articles