By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,722 Members | 1,259 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,722 IT Pros & Developers. It's quick & easy.

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

P: n/a
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[i]) 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
Sep 19 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

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[i]) == 0)
return true;
}

return false;
}

--
Tom Shelton

Sep 19 '06 #2

P: n/a
o... x.Equals(y[i])

--
William Stacey [MVP]

"Tom Shelton" <to*@mtogden.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
|
| 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[i]) == 0)
| return true;
| }
|
| return false;
| }
|
| --
| Tom Shelton
|
Sep 20 '06 #3

P: n/a

William Stacey [MVP] wrote:
o... x.Equals(y[i])
Yep... That works as well :)

--
Tom Shelton

Sep 20 '06 #4

P: n/a
Thanks everyone.
Vanderghast, Access MVP
"Tom Shelton" <to*@mtogden.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>
William Stacey [MVP] wrote:
>o... x.Equals(y[i])

Yep... That works as well :)

--
Tom Shelton

Sep 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.