How to implement customized List<T>.Contains()?

I need to implement a customized List<T>.Contains(). Here is what I have:

Public class MyType
{
public name{get;set;}
public location(get;set;}
public ID {get;set;}
}

public class MyTypeCollection: List<MyType>
{
......

public bool Contains(string name)
{
    // Need to compare the Name property
foreach(MyType item in xxx)
{
    .......
}
}
}

How do I refer the list in foreach statement:  what should I replace XXX with?

Anyone can help?

Thanks a lot.
LVL 1
chuang4630Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

p_davisCommented:
maybe

foreach(MyType item in this)
0
chuang4630Author Commented:
I have tried it and it does not work
0
p_davisCommented:
sorry i thought you were just overriding the contains method -- you are making your own overloaded method --- i need more information on what you are trying to do to advise then as it seems you are looking for some kind of string value against a property of an object in a list of your object type
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

chuang4630Author Commented:
The criteria is that if the Names are equal, then they are considered as duplicate, regardless the Location and ID.

I am thinking about implement the Equals in MyType:

public class MyType : IEquatable<Server>
{

public name{get;set;}
public location(get;set;}
public ID {get;set;}

        public bool Equals(MyType other)
        {
            return this.Name == other.Name;

        }
}

Will that work?
0
p_davisCommented:
i don't think you have to specifically impelement that interface to overrice equals.....


just try, in your class

public override bool Equals(Object obj)
    :base(object obj)
{}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
p_davisCommented:
or don't even call the base since you are trying to replace instead of append functionality
0
chuang4630Author Commented:
I need to verify that
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.