private void CheckForNewItems()
{
var items = GetChangedItems();
if (items != null)
{
foreach (var item in items )
{
var itemDB= GetItem(item.id);
if (itemDB!=null)
{
itemDB.somevalue= item.somevalue;
SaveToDatabase(itemDB);
}
}
}
}
I Write alot of code similar to the code above. Is there a smarter way to check for nulls in this scenario? Is "if(item!=null)" effecient? Do i even have to check for nulls?
Regards
GetChangedItems()method returns an empty array (and not null), you don't have to check ifitemsis null before the foreach loop.