Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

c# Typed List - Contains

Status
Not open for further replies.

Badgers

Programmer
Nov 20, 2001
187
US
Hi

I have the following list object.

List<ChannelsSelected> ChannelIDList = new List<ChannelsSelected>();

The class is:

public ChannelsSelected(int ChannelID, Boolean IsPrimaryChannel)
{
_ChannelID = ChannelID;
_IsPrimaryChannel = IsPrimaryChannel;
}

public int _ChannelID { get; set; }
public Boolean? _IsPrimaryChannel { get; set; }

The problem I have when adding is how to check if an object already exists.

ChannelIDList.Add(new ChannelsSelected(1, false));

What I am interested in checking is whether the ChannelID already exists within the typed list.

Thanks.
 
override the gethashcode and equals properties and compare on the business signature. there are examples of how to accomplish this online. NHibenrate is an ORM tool which requires this to properly unique entities and value objects. I mention this because you most likely run across the term while search for override gethashcode.

along with this you can also implment the IEquatible<T> interface which you can use to compare objects with custom logic.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top