Say you had this:
class A
{
public string name;
}
And then you have a List<A> and want to print the name of each object.
Normally, if you wanted to just print the items, you’d do something like
String.Join(", ", myList);
But I need to print the name property, not the myList object names. Is there an easier way than a foreach?
Use
For it you have to include
System.LinqnamespaceEDIT:
If you want to go for Adam’s answer after his code do what this
Courtesy Adam Goss comment on answer:
You wouldn’t need to call
.Select(x => x.ToString())as it would be called internally by object insideString.Join(), so if you overrideToString(), you just callString.Join(", ", myList);So after his code do what you had thought