using System;
using System.Collections.Generic;
using System.Linq;
namespace Generics1
{
class Program
{
static void Main(string[] args)
{
List<Animal> objects=new List<Animal>();
objects.Add(new Animal("Hachico"));
objects.Add(new Animal("Krypto"));
objects.Add(new Animal("Balto"));
objects.Add(new Animal("Gray"));
objects.Insert(0,new Animal("Alex"));
Console.WriteLine("The number of items in List is:{0}",objects.Count());
foreach(Animal o in objects)
{
Console.WriteLine(o.Name);
}
objects.RemoveAt(4);
Console.WriteLine("After Removal");
foreach (Animal o in objects)
{
Console.WriteLine(o.Name);
}
Console.ReadKey();
}
}
class Animal
{
public String Name{ get; set; }
public Animal(String name)
{
Name=name;
}
}
}
using System.Collections.Generic;
using System.Linq;
namespace Generics1
{
class Program
{
static void Main(string[] args)
{
List<Animal> objects=new List<Animal>();
objects.Add(new Animal("Hachico"));
objects.Add(new Animal("Krypto"));
objects.Add(new Animal("Balto"));
objects.Add(new Animal("Gray"));
objects.Insert(0,new Animal("Alex"));
Console.WriteLine("The number of items in List is:{0}",objects.Count());
foreach(Animal o in objects)
{
Console.WriteLine(o.Name);
}
objects.RemoveAt(4);
Console.WriteLine("After Removal");
foreach (Animal o in objects)
{
Console.WriteLine(o.Name);
}
Console.ReadKey();
}
}
class Animal
{
public String Name{ get; set; }
public Animal(String name)
{
Name=name;
}
}
}
Comments
Post a Comment