0
我在OS X下使用C#與.NET Core 1.1(目標框架爲netstandard1.6
),我得到一個奇怪的錯誤,爲一個缺少的方法。陣列不包含「AsReadOnly」的定義
using System;
using System.Collections.ObjectModel;
class Program
{
static void Main()
{
int[] array = { 1, 2, 3 };
ReadOnlyCollection<int> result = Array.AsReadOnly(array);
}
}
程序的編制在上面的錯誤結果顯示
error CS0117: 'Array' does not contain a definition for 'AsReadOnly'
是AsReadOnly
在.NET核心不可用,或者我失去了什麼東西?
根據https://docs.microsoft.com/en-us/dotnet/api/system.array.asreadonly--1?view=netstandard-1.6#System_Array_AsReadOnly__1___0___,它看起來不受支持。 – vyrp
但是你總是可以做'新的ReadOnlyCollection(array)' – vyrp
這個實現只是'返回新的ReadOnlyCollection(array);'所以我想你可以這樣做。 –