当我尝试隐式转换时,会得到以下错误:
Cannot implicitly convert type 'System.Array' to 'System.Collections.Immutable.ImmutableArray<Type>'当我试图显式转换时,我会得到以下错误:
Cannot convert type 'System.Array' to 'System.Collections.Immutable.ImmutableArray'
Cannot convert to static type 'System.Collections.Immutable.ImmutableArray'发布于 2015-08-28 18:29:18
使用ImmutableArray.Create([])进行转换:
var immutableArray = ImmutableArray.Create(yourArray);发布于 2015-08-28 18:28:07
IReadOnlyCollection是你要找的东西。
发布于 2015-08-28 18:33:04
public static ImmutableArray<T> Create<T>(T[] items)
{
if (items.length == 0)
{
// Avoid allocating an array.
return Create<T>();
}
var array = new T[items.length];
for (int i = 0; i < items.length; i++)
{
array[i] = items[i];
}
return new ImmutableArray<T>(array);
}使用上述代码,您可以创建一个ImmutableArray。打电话
return Create(yourArrayHere);https://stackoverflow.com/questions/32277483
复制相似问题