Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将System.Array转换为System.Collections.Immutable.ImmutableArray?_C# - Fatal编程技术网

C# 如何将System.Array转换为System.Collections.Immutable.ImmutableArray?

C# 如何将System.Array转换为System.Collections.Immutable.ImmutableArray?,c#,C#,当我尝试隐式转换时,会出现以下错误: Cannot implicitly convert type 'System.Array' to 'System.Collections.Immutable.ImmutableArray<Type>' IReadOnlyCollection是您要查找的内容。用于执行转换: var immutableArray = ImmutableArray.Create(yourArray); 看起来你把ImmutableArray和ImmutableAr

当我尝试隐式转换时,会出现以下错误:

Cannot implicitly convert type 'System.Array' to 'System.Collections.Immutable.ImmutableArray<Type>'

IReadOnlyCollection是您要查找的内容。

用于执行转换:

var immutableArray = ImmutableArray.Create(yourArray);

看起来你把
ImmutableArray
ImmutableArray
搞混了,但是因为你没有显示任何代码,所以很难说。你说得对,谢谢。这就是我最后使用的。谢谢我在使用System.Array vs MyType[]时遇到了另一个问题。
var immutableArray = ImmutableArray.Create(yourArray);
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);
            }
return Create(yourArrayHere);