public SPListItemCollection GetACollection()
{
try
{
//Method to get an item collection from somewhere
if(itemCol != null)
return itemCol;
else
return null;
}
catch(Exception ex)
{
LogException(ex);
return null;
}
}
此方法必須返回null(不是空列表) - 無論是否捕獲到異常。上述作品 - 但有沒有更好的方法呢?從try ...中返回null的方法... catch
我只是不明白你爲什麼需要'if-else'。 – Leri
你可以在try中做:return itemCol;而不是if/else。 – RvdK
如果'itemCol'是一個_empty_列表(包含0個項目的集合實例),它仍然會被返回。 –