Private void test (){
List <ITT
> TS = new list <ITT
> ();
TS. Add (New TT ("rongs", 10, "zhutou "));
TS. Add (New TT ("Rongrong", 10, "zhutou "));
TS. Add (New TT ("RR", 10, "zhutou "));
TS. Add (New TT ("WGR", 10, "zhutou "));
Tt t = new TT ("WGR", 10, "zhutou ");
Bool BC = ts. Contains
(T );
Console. writeline (BC); // true
}
// Extend this function to compare the two sets in detail
Private list <ITT
> Finddif (list <ITT
> Ts1, list <ITT
> Ts2 ){
List <ITT
> Dift = new list <ITT
> ();
If (ts1 = NULL | ts1.count = 0 ){
Return ts2;
}
Foreach (ITT t
In ts2 ){
If (! Ts1.contains (T
)){
Dift. Add (T
);
}
}
Return dift;
}
Public interface ITT
: Iequatable
<ITT
> {
String name {Get; set ;}
String address {Get; set ;}
Int age {Get; set ;}
}
Public class TT: ITT {
Public TT (string name, int age, string address ){
This. Name = Name;
This. Age = age;
This. Address = address;
}
Private string name;
Public string name {
Get {return name ;}
Set {name = value ;}
}
Private int age;
Public int age {
Get {return age ;}
Set {age = value ;}
}
Private string address;
Public String address {
Get {return address ;}
Set {address = value ;}
}
# Region iequatable <tt> Members
Public bool equals (ITT other ){
Return name. Equals (other. Name) & age. Equals (other. Age) & address. Equals (other. Address );
}
# Endregion
}
Msdn references
List <
(
<
(
T
>
)
>
)
.
.
::
.
Contains
Method
This method determines equality using the default equality comparer equalitycomparer <
(
<
(
T>
)
>
)
.
.
::
.
Default
For
T
, The type of values in the list.
Equalitycomparer <
(
<
(
T>
)
>
)
.
.
::
.
Default
The default
Property checks whether type T
Implements the system.
.
::
.
Iequatable <
(
<
(
T>
)
>
)
Generic interface and if so returns an equalitycomparer <
(
<
(
T>
)
>
)
That uses that implementation.
Otherwise it returns an equalitycomparer <
(
<
(
T>
)
>
)
That uses the overrides of object.
.
::
.
Equals
And object.
.
::
.
Gethashcode
Provided by T
.