关于字符串数组的一个疑惑,忘解答,,
如题,现在我有几行代码是这样的,
- C# code
string file = Request["XXX"] == null ? "" : Request["XXX"];string[] filePath = (file.IndexOf(',') > -1) ? file.Split(',') : {file};
这样就会报错,
但是我改成下面这样就不会出错
- C# code
string file = Request["XXX"] == null ? "" : Request["XXX"];string[] test = { file };string[] filePath = (file.IndexOf(',') > -1) ? file.Split(',') : test;
请问这是什么原因,,求解答,,谢谢。
[解决办法]
可以改成
new String[]{file};
[解决办法]
string[] test = { file };
这属于初始化,可以这样,报错的那个属于=号赋值,不可以类型不一致
[解决办法]