Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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
Linq 将MultiSelectList.SelectedValues转换为字符串[]的最小代码_Linq_Asp.net Mvc 4_Casting - Fatal编程技术网

Linq 将MultiSelectList.SelectedValues转换为字符串[]的最小代码

Linq 将MultiSelectList.SelectedValues转换为字符串[]的最小代码,linq,asp.net-mvc-4,casting,Linq,Asp.net Mvc 4,Casting,这是转换为字符串[]所必需的全部内容吗 string[] waterfrontoptions = Model.WaterfrontOptions. SelectedValues.Cast<String>() == null ? Model.WaterfrontOptions.SelectedValues.Cast<String>().ToArray() : null; string[]waterfrontoptions=Model.waterfront

这是转换为字符串[]所必需的全部内容吗

string[] waterfrontoptions = Model.WaterfrontOptions.
    SelectedValues.Cast<String>() == null 
    ? Model.WaterfrontOptions.SelectedValues.Cast<String>().ToArray() : null;
string[]waterfrontoptions=Model.waterfrontoptions。
SelectedValues.Cast()==null
? Model.WaterfrontOptions.SelectedValues.Cast().ToArray():null;

我只想在.SelectedValues属性中的值上添加一个.Contains。不,太多了
SelectedValues.Cast()
从不为空。如果
SelectedValues
为null,则
Cast
将引发异常。你可以做:

Model.WaterfrontOptions.SelectedValues.OfType<string>().Contains(xxxx);
我假设
WaterfrontOptions
SelectedValues
都不能为
null
(因为您的原始代码具有
SelectedValues.Cast

Model.WaterfrontOptions.SelectedValues.Select(v => v.ToString()).Contains(xxxx);