У меня есть массив, который, как я знаю, выиграл не изменится, и я хочу создать ImmutableArray, чтобы клиенты могли безопасно получать доступ к моему массиву.
Глядя на исходный код ImmutableArray, я вижу, что метод Create не поможет:
Глядя на исходный код ImmutableArray, я вижу, что метод Create не поможет:
р>
Код: Выделить всё
public static ImmutableArray Create(params T[] items)
{
if (items == null)
{
return Create();
}
// We can't trust that the array passed in will never be mutated by the caller.
// The caller may have passed in an array explicitly (not relying on compiler params keyword)
// and could then change the array after the call, thereby violating the immutable
// guarantee provided by this struct. So we always copy the array to ensure it won't ever change.
return CreateDefensiveCopy(items);
}
п>
Подробнее здесь: https://stackoverflow.com/questions/513 ... ut-copying