Please review the two code snippets below and let me know if the second snippet is better than the first one.
In code snippet 2 I have added an inline function. According to my peers, using inline functions can help improve performance, since context switch will occur less often.
But I am not able to verify this claim. Is there any perfomance difference in the two code snippets?
Snippet 1
foreach (var item in requestPayLoad.UserData)
{
UserItem userItem = UserItemHelper.CreateItem(item, jobID);
if (userItem != null)
{
lstUserItems.Add(userItem);
}
}
Snippet 2
var GetUserItem = new Func<UserItem , UserJob , UserItemStruct>((custItemStruct, syncJob) =>
{
return UserItemHelper.CreateItem(custItemStruct, syncJob);
});
foreach (var item in requestPayLoad.UserData)
{
UserItem userItem = GetUserItem(item,job);
if (userItem != null)
{
lstUserItems.Add(userItem);
}
}