日期:2014-05-18  浏览次数:20848 次

关于字符串数组的一个疑惑,忘解答,,
如题,现在我有几行代码是这样的,
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 };
这属于初始化,可以这样,报错的那个属于=号赋值,不可以类型不一致
------解决方案--------------------
探讨
可以改成
new String[]{file};