D
DNB
I am using generic in the following example.
But I can figure out how to remove an item in the collection??
Thanks
DNB
------------------------------------------------------------------------------------------------
using System.Collections.Generic;
using System.Text;
protected void Page_Load(object sender, EventArgs e)
{
//Generic List Creation
//List is a Generic Class provided by .Net Framework 2.0
//System.Collections.Generics is the Namespace.
List<Person> myPerson = new List<Person>();
myPerson.Add(new Person("1 Test"));
//IF I have to remove "2 Test" how can I do that in the code mentioned
below
myPerson.Add(new Person("2 Test"));
myPerson.Add(new Person("3 Test", 24, "tt"));
myPerson.Add(new Person("4 Test", 24, "tt"));
foreach (Person p in myPerson)
{
Response.Write(p.Name);
Response.Write(" ");
Response.Write(p.Age);
Response.Write(" ");
Response.Write(p.Address);
Response.Write(" ");
Response.Write(p.Company);
Response.Write("<br>");
}
//IF I have to remove "2 Test" how can I do that
}
}
class Person
{
int _Age;
public int Age
{
get { return _Age; }
set { _Age = value; }
}
String _Name;
public String Name
{
get { return _Name; }
set { _Name = value; }
}
String _Address;
public String Address
{
get { return _Address; }
set { _Address = value; }
}
String _Company;
public String Company
{
get { return _Company; }
set { _Company = value; }
}
public Person() { }
public Person(String Name)
{
this.Name = Name;
this.Age = 0;
this.Address = String.Empty;
this.Company = String.Empty;
}
public Person(String Name, int Age, String Address)
{
this.Name = Name;
this.Age = Age;
this.Address = Address;
}
}
But I can figure out how to remove an item in the collection??
Thanks
DNB
------------------------------------------------------------------------------------------------
using System.Collections.Generic;
using System.Text;
protected void Page_Load(object sender, EventArgs e)
{
//Generic List Creation
//List is a Generic Class provided by .Net Framework 2.0
//System.Collections.Generics is the Namespace.
List<Person> myPerson = new List<Person>();
myPerson.Add(new Person("1 Test"));
//IF I have to remove "2 Test" how can I do that in the code mentioned
below
myPerson.Add(new Person("2 Test"));
myPerson.Add(new Person("3 Test", 24, "tt"));
myPerson.Add(new Person("4 Test", 24, "tt"));
foreach (Person p in myPerson)
{
Response.Write(p.Name);
Response.Write(" ");
Response.Write(p.Age);
Response.Write(" ");
Response.Write(p.Address);
Response.Write(" ");
Response.Write(p.Company);
Response.Write("<br>");
}
//IF I have to remove "2 Test" how can I do that
}
}
class Person
{
int _Age;
public int Age
{
get { return _Age; }
set { _Age = value; }
}
String _Name;
public String Name
{
get { return _Name; }
set { _Name = value; }
}
String _Address;
public String Address
{
get { return _Address; }
set { _Address = value; }
}
String _Company;
public String Company
{
get { return _Company; }
set { _Company = value; }
}
public Person() { }
public Person(String Name)
{
this.Name = Name;
this.Age = 0;
this.Address = String.Empty;
this.Company = String.Empty;
}
public Person(String Name, int Age, String Address)
{
this.Name = Name;
this.Age = Age;
this.Address = Address;
}
}