سلام بر تمامی برنامه نویسان #C 😉 در این مطلب آموزش Generic IEquatable « Generic Interface در سی شارپ #C را آماده کردم. انشاالله که این آموزش برای شما مفید باشد.
کد Generic IEquatable « Generic Interface در سی شارپ #C :
using System;
using System.Collections.Generic;
using System.ComponentModel;
public sealed class Pair<TFirst, TSecond>: IEquatable<Pair<TFirst, TSecond>>{
private readonly TFirst first;
private readonly TSecond second;
public Pair(TFirst first, TSecond second)
{
this.first = first;
this.second = second;
}
public TFirst First
{
get { return first; }
}
public TSecond Second
{
get { return second; }
}
public bool Equals(Pair<TFirst, TSecond> other)
{
if (other == null)
{
return false;
}
return EqualityComparer<TFirst>.Default.Equals(this.First, other.First) &&
EqualityComparer<TSecond>.Default.Equals(this.Second, other.Second);
using System.Collections.Generic;
using System.ComponentModel;
public sealed class Pair<TFirst, TSecond>: IEquatable<Pair<TFirst, TSecond>>{
private readonly TFirst first;
private readonly TSecond second;
public Pair(TFirst first, TSecond second)
{
this.first = first;
this.second = second;
}
public TFirst First
{
get { return first; }
}
public TSecond Second
{
get { return second; }
}
public bool Equals(Pair<TFirst, TSecond> other)
{
if (other == null)
{
return false;
}
return EqualityComparer<TFirst>.Default.Equals(this.First, other.First) &&
EqualityComparer<TSecond>.Default.Equals(this.Second, other.Second);