求助List select(c=>c.Id=value).toList<T>() 报错
private void SelectFiles<T>(string isReadyOnly)
{
if (typeof(T).ToString() == "System.IO.FileInfo")
{
// var Lists = fileInfoList;
fileInfoList = fileInfoList.Select(c => c.IsReadOnly = isReadyOnly).ToList<T>();
}
else
{
throw new Exception("文件夹不存在IsReadOnly属性。");
}
}
如题如代码,错误为:
Error 2 Instance argument: cannot convert from 'System.Collections.Generic.IEnumerable<bool>' to 'System.Collections.Generic.IEnumerable<T>' C:\Documents and Settings\yuxiangyong\My Documents\Visual Studio 2008\Projects\WPFFolderManager\WPFFolderManager\FileManager.xaml.cs 119 32 WPFFolderManager
在线等!
------解决方案--------------------fileInfoList = fileInfoList.Select(c => c.IsReadOnly =
= isReadyOnly).ToList<T>();
是不是少个等号呀
------解决方案-------------------- fileInfoList = fileInfoList.Select(c => c.IsReadOnly = isReadyOnly).ToList<T>();
c.IsReadOnly==isReadyOnly
需要比较的不是赋值
------解决方案--------------------
fileInfoList = fileInfoList.Select(c => c.IsReadOnly = isReadyOnly).ToList<T>();
貌似你的Select应该为Where,如果isReadyOnly是个查询条件,修改为下面这样
fileInfoList = fileInfoList.Where(c => c.IsReadOnly == isReadyOnly).ToList<T>();
------解决方案--------------------看看再说.
------解决方案-------------------- fileInfoList = fileInfoList.Where(c => c.IsReadOnly == isReadyOnly).ToList<T>();
------解决方案--------------------c.IsReadOnly 是个bool类型
而isReadyOnly参数是个string类型
八成是这个原因
------解决方案--------------------
如果仅仅是加个Where判断,写成下面就行了
fileInfoList = fileInfoList.Where(c => c.IsReadOnly == isReadyOnly).ToList();
------解决方案--------------------
错误提示是什么
------解决方案--------------------