473,396 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
4 1942

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
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

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

--
Tom Shelton

Sep 20 '06 #4
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Scott Brady Drummonds | last post by:
Hi, everyone, I've checked a couple of on-line resources and am unable to determine how reinterpret_cast<> is different from static_cast<>. They both seem to perform a compile-time casting of...
1
by: verec | last post by:
Last week I asked here how I could detect that a T was polymorphic, and received very thoughtful and useful replies that I used straight away. Thanks to all who answered. This week, it turns...
2
by: ESPNSTI | last post by:
Hi, I'm trying to use a generics dictionary with a key class that implements and needs IComparable<>. However when I attempt to use the dictionary, it doesn't appear to use the IComparable<> to...
9
by: Simple Simon | last post by:
Java longs are 8 bytes. I have a Java long that is coming in from the network, and that represents milliseconds since Epoch (Jan 1 1970 00:00:00). I'm having trouble understanding how to get it...
45
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies...
3
by: Samuel R. Neff | last post by:
You can you program against generic interfaces generically? For example, how can I make the following code which works for the non-generic interface also work for the generic counterparts? ...
2
by: Savior | last post by:
then find out what is T?
3
by: TonyJ | last post by:
Hello! I'm reading in a book from Microsoft that the generic interface IComparabler<Tdefine the two methods CompareTo and Equals. Now to my querstion if I look in the docs it says that...
1
by: Tony Johansson | last post by:
Hello!¨ I read a book and here it says that it's most often an advantage to implement the generic interface IComparable<T> instead of the general interface IComparable. This is correct! Now...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.