有没有办法将单个对象T转换为T[]
使用它的一个例子是在将单个传递给string需要a的函数时string[]
例
void ExistingMethod(string[] sa);
void main()
{
string s;
ExistingMethod(s); //<= problem is there a syntax that allows this type of cast?
}
Run Code Online (Sandbox Code Playgroud)
对这样的解决方案不感兴趣
string [] singleElementArray = new string[1];
singleElementArray[0] = s;
ExistingMethod(singleElementArray)
Run Code Online (Sandbox Code Playgroud)
我想看看C#是否允许这种类型的铸造.
我以为我看到了Java允许它的一种方式,只需([s])用[] 将它包装起来即可.C#有这种语法吗?
注意,不想创建1的数组并分配它...