首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

关于字符串数组的一个疑惑,忘解答,解决思路

2012-04-13 
关于字符串数组的一个疑惑,忘解答,,如题,现在我有几行代码是这样的,C# codestring file Request[XXX]

关于字符串数组的一个疑惑,忘解答,,
如题,现在我有几行代码是这样的,

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};

热点排行