Given a = null Shouldn't this not throw an exception?
if(a != null && ((string)a).ToLower()=="boo"){
... operation
}
Due to lazy evaluation the second statement should never be called so this ((string)a).ToLower() shouldn't be throwing an exception right ?
UPDATE
IOrderedEnumerable<SPListItem> Items = sourceList.GetItems("ProjectID", "Title", "ProjectName", "Featured", "Size", "Description")
.Cast<SPListItem>().AsEnumerable().OrderBy((i => rnd.Next()));
SPListItemCollection randProjImages = SPContext.Current.Web.Lists.TryGetList("Random Projects Images").GetItems();
var randomImgNrs = Enumerable.Range(0, randProjImages.Count).OrderBy(i => rnd.Next()).ToArray();
Dictionary<string, string> projectImages = new Dictionary<string,string>();
IEnumerable<SPListItem> projImages = SPContext.Current.Web.Lists.TryGetList("Assigned Projects Images").
GetItems().Cast<SPListItem>().AsEnumerable();
foreach (SPListItem it in projImages) projectImages.Add((string)it["ProjectID"], (string)it["ServerUrl"]);
int qCount = 0;
foreach (SPListItem item in Items) {
if (item["Size"] != null && item["Featured"]!=null &&
((string)item["Size"]).ToLower() == "big" || ((string)item["Featured"]).ToLower() == "yes") {
dataItems.Add(new Project(item["ProjectID"].ToString(), (string)item["Title"],
"/sites/Galileo/SitePages/" + Utils.getCurrentLang().ToLower() + "/Projects.aspx#id=pwp" + item["ProjectID"],
projectImages[(string)item["ProjectID"]],
Utils.truncateString(item.Fields["Description"].GetFieldValueAsText(item["Description"]), 175), "project"));
}else{
Replacing the foreach with this:
foreach (SPListItem item in Items) {
var k = item["Size"];
if (item["Size"] != null && item["Featured"]!=null &&
((string)item["Size"]).ToLower() == "big" || ((string)item["Featured"]).ToLower() == "yes") {
dataItems.Add(new Project(item["ProjectID"].ToString(), (string)item["Title"],
"/sites/Galileo/SitePages/" + Utils.getCurrentLang().ToLower() + "/Projects.aspx#id=pwp" + item["ProjectID"],
projectImages[(string)item["ProjectID"]],
Utils.truncateString(item.Fields["Description"].GetFieldValueAsText(item["Description"]), 175), "project"));
}else{
And breaking just before the if statement in the debugger, k == null