473,804 Members | 3,433 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

nested generic class

How will this actually work:

public class Foo<T>
{

public class Bar<T>
{
private T t;

}
}
public class Test
{
public static void Main(string []args)
{
Foo<intfoo=new Foo<int>(); ///???

}
}
will this cause the nested Bar class, at run time, to become closed
time using int?

Becoming something like this:

public class Foo<int>
{

public class Bar<int>
{
private T t;

}
}

Thanks
Oct 18 '08 #1
2 1753
On Sat, 18 Oct 2008 11:49:00 -0700, puzzlecracker <ir*********@gm ail.com>
wrote:
How will this actually work:
Looks like another great opportunity for you to fire up Visual Studio and
try it yourself.

If after doing that you have some specific question about what _does_
happen, that would be a question worth answering.

Pete
Oct 18 '08 #2
puzzlecracker <ir*********@gm ail.comwrote:
How will this actually work:

public class Foo<T>
{

public class Bar<T>
{
private T t;

}
}

public class Test
{
public static void Main(string []args)
{
Foo<intfoo=new Foo<int>(); ///???

}
}
will this cause the nested Bar class, at run time, to become closed
time using int?
Well you haven't referred to a nested Bar class at all. However, Bar
defines its own type parameter, which hides Foo's. They're separate
type parameters though.

In other words, you can specify Foo<string>.Bar <int>.

For further nested generic type weirdness, see this post from Cyrus:
http://blogs.msdn.com/cyrusn/archive...01/446431.aspx

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Oct 19 '08 #3

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

Similar topics

2
1281
by: RYoung | last post by:
Hello all, Given this C# generic class definition: class Command<Key, Data> { BerkeleyParameter<Key> key; BerkeleyParameter<Data> data; public void AddParameters(BerkeleyParameter<Key> key,
2
1645
by: RFOG | last post by:
Hi all! I need a class that will be capable to enumerate some internal data, then my idea is to implement "for each" loop access. Doc says that I've to inherit form IEnumerable, but then compiler says "Error 1 error C2955: 'System::Collections::Generic::IEnumerable' : use of class generic requires generic argument list" I understand that my class have to be a generic class, but I don't need that.
2
3367
by: Rune Vistnes | last post by:
Hey, I am trying to wrap an unmanaged library in managed c++ so that I can use this library in other .NET languages, such as C#. I've been successful for the most part this far, but I'm having a hard time figuring out how to wrap template classes. I'm getting an C3231 compile error when I try to use the generic type as a template type. Here's an example from the MSDN C3231 compile error site:
2
9872
by: AdawayNoSpam | last post by:
Said that I have the following class Class MyRootClass(Of T) End Class Class MySubClass1(Of T) Inherits MyRootClass(Of T) End Class
4
9176
by: Hyun-jik Bae | last post by:
Is that not allowed to assume generic type numeric type? As far as I've tried, I got an error with the following code: public class AAA<T> { public int Foo(T a) { return a; // error: Cannot implicitly convert type 'T' to 'int' } }
7
38616
by: Andrus | last post by:
public class BusinessObjectGeneric<EntityType: BusinessObject where EntityType : BusinessEntity, new() { public BusinessObjectGeneric<EntityType() { } ..... causes error in constructor declaration:
10
1941
by: Egghead | last post by:
Hi all, Can someone kindly enough point me to some situations that we shall or "must" use Generic Class? I can foresee the Generic Method is powerful, but I can not find a single situation that I will need the Generic Class, given there are so many other options. -- cheers,
10
2964
by: fig000 | last post by:
HI, I'm new to generics. I've written a simple class to which I'm passing a generic list. I'm able to pass the list and even pass the type of the list so I can use it to traverse it. It's a generic list of business objects. I'm able to see that the type is the correct one in the debugger. However when I try to traverse the list using the type I can't compile. The same type variable I've verified as being passed
1
2460
by: raylopez99 | last post by:
Here is an example of a home grown generic class, representing a pair of values. Adapted from Jon Skeet's book "C# In Depth". The generic class is "sealed" for some reason (I think for performance) so you cannot derive from it, but that's optional. The main thing in this example is to show the right format for using these generic classes, which was not present in the code snippet in Skeet's book. Does anybody know why the .Equals...
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
7616
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.