|
using System;
using System.Collections;
namespace CollectionTest
{
/// <summary>
/// Student Class with 3 properties.
/// </summary>
public class Student
{
string name="";
public string Name
{
get{return name;}
set{name = value;}
}
int id=0;
public int Id
{
get{return id;}
set{id = value;}
}
DateTime dob=DateTime.MinValue;
public DateTime DOB
{
get{return dob;}
set{dob = value;}
}
public Student(string name,int id,DateTime Dob)
{
this.name = name;
this.id = id;
this.dob = Dob;
}
}//Student class
/// <summary>
/// Note : This student collection inherhits SortableCollectionBase
/// In the constructor set the SortObjectType for sorting.
/// </summary>
public class StudentCollection : SortableCollectionBase
{
#region CollectionBase implementation
public StudentCollection()
{
//In your collection class constructor add this line.
//set the SortObjectType for sorting.
base.SortObjectType = typeof(Student);
}
public Student this[ int index ]
{
get
{
return( (Student) List[index] );
}
set
{
List[index] = value;
}
}
public int Add( Student value )
{
return( List.Add( value ) );
}
public int IndexOf( Student value )
{
return( List.IndexOf( value ) );
}
public void Insert( int index, Student value )
{
List.Insert( index, value );
}
public void Remove( Student value )
{
List.Remove( value );
}
public bool Contains( Student value )
{
// If value is not of type Int16, this will return false.
return( List.Contains( value ) );
}
protected override void OnInsert( int index, Object value )
{
// Insert additional code to be run only when inserting values.
}
protected override void OnRemove( int index, Object value )
{
// Insert additional code to be run only when removing values.
}
protected override void OnSet( int index, Object oldValue, Object newValue )
{
// Insert additional code to be run only when setting values.
}
protected override void OnValidate( Object value )
{
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.