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.
class Listobj
{
int age;
string name;
public int Age
{
get { return age; }
set { age = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
static List<Listobj> newlist = new List<Listobj>();
static void Main(string[] args)
{
/*newlist.Add(10);
newlist.Add(2);
newlist.Add(6);
newlist.Sort();
newlist.ForEach(Console.WriteLine);
Console.ReadLine();*/
Listobj obj = new Listobj();
int tempage = 23;
string tempname = "deepak";
obj.Age = tempage;
obj.Name = tempname;
Listobj.newlist.Add(obj);
foreach (Listobj item in newlist)
Console.WriteLine(item);
Console.ReadLine();
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…