473,405 Members | 2,310 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,405 software developers and data experts.

Generics - How do you do this in one class?

How do you do this with one class instead of two?

This works:

public class UlMenu1<T> where T : UlMenuItem
{

}

// I want UlMenu2 to implement IComparable (UlBeverageItem already does,
but is not shown here).
public class UlMenu2 : UlTest1<UlBeverageItem>, IComparable
{
#region IComparable Members
public int CompareTo(object obj)
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
}
This does not mean the same thing:
public class UlMenu1<T> where T : UlMenuItem, IComparable
{
}

Also, how do you have a generic input item that must be a class and still
inherit from another class?
public class UlMenu1<T> where T : UlMenuItem :
UlBaseMenuClassForUlMenu1ToInheritFrom
{

}
Thanks,
Dave
Apr 13 '06 #1
2 1038
Dave,
How do you do this with one class instead of two?

This works:

public class UlMenu1<T> where T : UlMenuItem
{

}

// I want UlMenu2 to implement IComparable (UlBeverageItem already does,
but is not shown here).
public class UlMenu2 : UlTest1<UlBeverageItem>, IComparable
{
#region IComparable Members
public int CompareTo(object obj)
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
}
This does not mean the same thing:
public class UlMenu1<T> where T : UlMenuItem, IComparable
{
}

Not sure I understand the problem here. Are you looking for this?

public class UlMenu1<T> : IComparable where T : UlMenuItem,
{
}

Also, how do you have a generic input item that must be a class and still
inherit from another class?
public class UlMenu1<T> where T : UlMenuItem :
UlBaseMenuClassForUlMenu1ToInheritFrom
{

}

public class UlMenu1<T> : UlBaseMenuClassForUlMenu1ToInheritFrom where
T : UlMenuItem
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 14 '06 #2
Bingo on both...

Thanks!
Apr 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Luc Vaillant | last post by:
I need to initialise a typed parameter depending of its type in a generic class. I have tried to use the C++ template form as follow, but it doesn't work. It seems to be a limitation of generics...
5
by: anders.forsgren | last post by:
This is a common problem with generics, but I hope someone has found the best way of solving it. I have these classes: "Fruit" which is a baseclass, and "Apple" which is derived. Further I have...
1
by: Vladimir Shiryaev | last post by:
Hello! Exception handling in generics seems to be a bit inconsistent to me. Imagine, I have "MyOwnException" class derived from "ApplicationException". I also have two classes...
7
by: SpotNet | last post by:
Hello NewsGroup, Reading up on Generics in the .NET Framework 2.0 using C# 2005 (SP1), I have a question on the application of Generics. Knowingly, Generic classes are contained in the...
13
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.