TA.ServiceProxy.RoleManagement.GetSubPrivilagesResponses subPrivilagesResponses = GetSubPrivilagesFromPrivilageCodeStatic("Authoring01");
if (subPrivilagesResponses != null && subPrivilagesResponses.SubprivilagesList != null)
{
for (int j = 0; j < subPrivilagesResponses.SubprivilagesList.Length; j++)
{
if (subPrivilagesResponses.SubprivilagesList[j].PrivilageCode == "CREATOR")
{
objTemplate.IsTagged = true;
break;
}
}
}
The above code is written as
TA.ServiceProxy.RoleManagement.GetSubPrivilagesResponses subPrivilagesResponses = GetSubPrivilagesFromPrivilageCodeStatic("Authoring01");
if (subPrivilagesResponses != null && subPrivilagesResponses.SubprivilagesList != null)
{
var item = subPrivilagesResponses.SubprivilagesList.SingleOrDefault(cd => cd.PrivilageCode == "CREATOR");
if(item != null && item.PrivilageCode == "CREATOR")
objTemplate.IsTagged = true;
}
In what are the different way it can be modified in order to boost performance and efficiency by making use of Lambda or LINQ
PrivilageCode == "CREATOR"
, while the second actually ensures that there is only one (or none) item having that predicate - if more items satisfy the condition aThrowMoreThanOneMatchException
exception is thrown. So they are not doing the exact same thing. Which one is the correct/preferred? \$\endgroup\$SingleOrDefault
. What are all possible ways to matchPrivilageCode == "CREATOR"
. I mean to say how can the above snippet can be rewritten in different possible ways to yield the above condition. Even I or the readers would benefit a lot @HenrikHansen \$\endgroup\$