In<T>(T x, params T[] y) where T:struct, IComparable<T>

  • Thread starter Thread starter Michel Walsh
  • Start date Start date
M

Michel Walsh

Question:

public static Boolean In<T>(T x, param T[ ] y) where T : struct,
IComparable<T>
{
for(int i=0; i<y.Length; i++)
{
if(x==y) return true;
}
return false;
}


generates the compilation error that == cannot be applied to operands of
type 'T' and 'T'...


Can it be corrected? (Cannot use Contains and a list, at that point, the
snippet is just a simplified illustration)



Vanderghast, Access MVP
 
Michel said:
Question:

public static Boolean In<T>(T x, param T[ ] y) where T : struct,
IComparable<T>
{
for(int i=0; i<y.Length; i++)
{ if (((IComparable
}
return false;
}
static bool In<T> (T x, params T[] args) where T : struct
{
for (int i = 0; i < args.Length; i++)
{
if (((IComparable<T>)x).CompareTo (args) == 0)
return true;
}

return false;
}
 
o... x.Equals(y)

--
William Stacey [MVP]

|
| Michel Walsh wrote:
| > Question:
| >
| > public static Boolean In<T>(T x, param T[ ] y) where T : struct,
| > IComparable<T>
| > {
| > for(int i=0; i<y.Length; i++)
| > {
| if (((IComparable
| > }
| > return false;
| > }
| >
| >
| static bool In<T> (T x, params T[] args) where T : struct
| {
| for (int i = 0; i < args.Length; i++)
| {
| if (((IComparable<T>)x).CompareTo (args) == 0)
| return true;
| }
|
| return false;
| }
|
| --
| Tom Shelton
|
 
Back
Top