473,385 Members | 1,429 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,385 software developers and data experts.

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 1736
On Sat, 18 Oct 2008 11:49:00 -0700, puzzlecracker <ir*********@gmail.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*********@gmail.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.com>
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
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>...
2
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...
2
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...
2
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
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...
7
by: Andrus | last post by:
public class BusinessObjectGeneric<EntityType: BusinessObject where EntityType : BusinessEntity, new() { public BusinessObjectGeneric<EntityType() { } ..... causes error in constructor...
10
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...
10
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...
1
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.