我想替换我所有的null值,List<string>
但是如果不想执行foreach循环。
List<string> tmpList = new List<string>();
//src is a List<string> where I want to remplace the null by "NULL"
foreach(string s in src)
{
if(s == null)
{
tmpList.Add("NULL");
}
else
{
tmpList.Add(s);
}
}
src = tmpList;
您知道更好的方法吗?用LINQ可能是?
src.Select(s => s ?? "NULL").ToList();
但是使用foreach循环有什么问题呢?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句