I have a list of objects, Model is:
public class Rule
{
public bool IsValid { get; set; }
public string RuleName { get; set; }
public string Description { get; set; }
}
To get values of RuleName and IsValid from a list of Rules I did the following:
string.Join(", ", list.Select(rule=> new { rule.RuleName, rule.IsValid }))
Current output is in the following format:
{ RuleName = name1, IsValid = True}, { RuleName = name2, IsValid = False }
How to convert it to a format similar to the following without using loops?
name1 is True, name2 is False
It's simple with String.Join
, Enumerable.Select
and string interpolation(C#6):
string.Join(", ", list.Select(r=> $"{r.RuleName} is {r.IsValid}"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With