convert foreach to linq c#
sequence.Where(x => x.Name.ToString().Equals("Apple"))
.ToList()
.ForEach( x =>
{
if(someCondition)
{
// Do some stuff here.
}
});
4.4
5
items.ToList().ForEach(i => i.DoStuff());
Thank you!
5
0
0
4
foreach (var customer in customers)
{
customer.Email = !string.IsNullOrEmpty(customer.Name) && !string.IsNullOrEmpty(customer.Last) ? $"{customer.Name}.{customer.Last}{customer.Email.Substring(customer.Email.IndexOf("@"))}" : customer.Email;
}
Thank you!
4
0
4
7
foreach (string field in fieldsList)
{
if (retrievedOrderLine.Attributes.Contains(field))
{
orderLine[field] = retrievedOrderLine[field];
}
}
Thank you!
7
0
Are there any code examples left?
New code examples in category C#