Does the enum IList <T> enumerate an array of type T [] to enumerate?

I have a method that looks like this:

T[] field;

public Method(IList<T> argument)
{
    this.field = (T[])argument;
}

When the method body is executed, does the enumeration occur during translation? Will this change if the base type is different?

+3
source share
2 answers

No, he will not list anything. This will either succeed if argumentit is T[], or throw an exception InvalidCastExceptionif it is not. (Or return null if argumentnull.)

+8
source

If it argumentis a reference to an array (of type T), then there is no enumeration - this is a simple actor.

argument List<T> , IList, . ( , T[] - , ).

: , , .

+4

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


All Articles