I created a list with Listobj object type. And added a set of values to the object.
How do I print the Listobj objects from the newlist in an increasing age fashion.
You can use Linq to order your list:
foreach (Listobj item in newlist.OrderBy(x => x.Age))
Console.WriteLine(item);
Also, a few improvements:
Which gives:
public class Listobj
{
public int Age { get; set; }
public string Name { get; set; }
public override string ToString()
{
return string.Format("My name is {0} and I'm {1} years old.", Name, Age);
}
}