C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Use Strong Collection Type while design class (Design own Collection data type)


Posted Date: 27 Jan 2006    Resource Type: Articles    Category: .NET Framework
Author: Vivekanan TawareMember Level: Bronze    
Rating: 1 out of 5Points: 7



While design the class in c# most of time we need use collection of this class. following exaple explain your how to design the customer class and its collection




class Customer
{
private string m_strName;

public string Name
{
get { return m_strName; }
set { m_strName = value; }
}

public Customer()
{

}

public Customer(string Name)
{
m_strName = Name;
}
}

///
/// This is a collection of Customer class
///

class Customers : CollectionBase
{
public int Add(Customer item)
{
return List.Add(item);
}

public void Remove(Customer item)
{
List.Remove(item);
}

public bool Contains(Customer item)
{
return List.Contains(item);
}

public int IndexOf(Customer item)
{
return List.IndexOf(item);
}

public void CopyTo(Customer[] array, int index)
{
List.CopyTo(array, index);
}

public Customer this[int index]
{
get { return (Customer)List[index]; }
set { List[index] = value; }
}
}

// How to use this Collection of class
Customer a1 = new Customer("Raj");
Customer a2 = new Customer("Vivek");
Customer a3 = new Customer("Parvin");
Customer a4 = new Customer("Taware");

Customers a = new Customers();
a.Add(a1);
a.Add(a2);
a.Add(a3);
a.Add(a4);

for(int i =0 ;i< a.Count;i++)
{
MessageBox.Show(a[i].Name);
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: The thing that happens behind the scenes!!!
Previous Resource: Simple Demonstration of Serialization and De-Serialization
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use