在foreach循环中的空异常处理 [英] Null Exception handling in foreach loop
本文介绍了在foreach循环中的空异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在检查每个循环中的条件。但是我不知道它是不正确的。
SPList _listObj = web.Lists [new Guid(listID)];
SPListItem item = _listObj.GetItemById(Convert.ToInt32(itemID));
foreach(_listObj.Fields中的SPField字段)
{
if(field.Title!= Null)
{//做一些代码}}
解决方案
请尝试以下代码:
< p $ p>
foreach(var x in Lists.Where(x => x.fiels!= null))
{
}
I am having the list X with some string and null value . I am iterating the foreach loop to bind the value to the textbox. If I get any null values in my list X the foreach loop get terminated and getting the null exception how to handle it.
I am checking the condition inside the for each loop. but i tnink it not correct logcally.
SPList _listObj = web.Lists[new Guid(listID)];
SPListItem item = _listObj.GetItemById(Convert.ToInt32(itemID));
foreach (SPField field in _listObj.Fields)
{
if (field.Title != Null)
{ //do some code}}
解决方案
Try below code:
foreach(var x in Lists.Where(x => x.fiels != null))
{
}
这篇关于在foreach循环中的空异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文