using System.Collections.Generic;
public static void Main()
Console.WriteLine("foo ToString = " + foo.ToString());
List<Foo> list = new List<Foo>();
for (int i = 0; i < 10; i++)
list.Add(new Foo{Id = i, Name = "foo " + i});
Console.WriteLine("list ToString = " + list.ToCustomString());
public override string ToString()
output += "Id:" + this.Id.ToString() + "\r\n";
output += "Name: " + this.Name + "\r\n";
public static class MyListOfFoosExtensions
public static string ToCustomString(this IEnumerable<object> list)
output += el.ToString() + "\r\n";