473,769 Members | 6,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

any possible use of this feature?

you can define two class with same name but having different generic
parameters in one assembly. As below:

class Gen<T>
{
}

class Gen<T1,T2>
{
}

any possible use of it?
Nov 16 '05 #1
9 1243
class name has to be unique within one namespace. If you have to define two
classes with same name, you can put them in different namespaces in one
assembly. C# class does not support template taking parameters like in C++

--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Justin Shen" <De*******@hotm ail.com> wrote in message
news:es******** ******@TK2MSFTN GP10.phx.gbl...
you can define two class with same name but having different generic
parameters in one assembly. As below:

class Gen<T>
{
}

class Gen<T1,T2>
{
}

any possible use of it?

Nov 16 '05 #2
Jiachuan Wang [MSFT] <ji*****@online .microsoft.com> wrote:
class name has to be unique within one namespace. If you have to define two
classes with same name, you can put them in different namespaces in one
assembly. C# class does not support template taking parameters like in C++


I think Justin was actually talking about the generics which will be
available in C# v2.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Justin Shen <De*******@hotm ail.com> wrote:
you can define two class with same name but having different generic
parameters in one assembly. As below:

class Gen<T>
{
}

class Gen<T1,T2>
{
}

any possible use of it?


Possibly - I could imagine something which would be like an array-list
but with multiple "dimensions ", each of which would be a different
type. For instance, you could do:

myList[10,"hello"] = "there";

With straight generics on ArrayList you could easily get to

myList[10]["hello"] = "there";

I suspect, but the first syntax might be better in some circumstances.

Probably not *really* useful, but just an idea of how it might be used.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

"Justin Shen" <De*******@hotm ail.com> wrote in message
news:es******** ******@TK2MSFTN GP10.phx.gbl...
you can define two class with same name but having different generic
parameters in one assembly. As below:

class Gen<T>
{
}

class Gen<T1,T2>
{
}

any possible use of it?

I don't think you'll find *many* useful uses for it. In most of the
scenarios I can think of, a base class would have to exist already, often
times making the usage of generics less valuable. In those cases I can think
of a particular usage of this that wouldn't require a new base class(where
Gen<T> could be used as the base), I think the other class should probably
have an entirely different name.

It does make one wonder if syntax could be formed that would allow a sort of
generic overloading, so that one class could take, for example, from 1 to 3
types. I'm not sure of the explicit value of that either, but it would be
more interesting and probably more flexible than the above concept.
Nov 16 '05 #5
Justin Shen wrote:
you can define two class with same name but having different generic
parameters in one assembly. As below:

class Gen<T>
{
}

class Gen<T1,T2>
{
}


Assuming you're talking about C# 2.0 (Whidbey), are you sure that you
can do this? I haven't played around with Whidbey much, but my reading
of the draft spec indicates that this is not supported (from Section 20.1):

=============== =============== =============== =============== =====
Generic types may not be “overloaded”, that is the identifier of a
generic type must be uniquely named within a scope in the same way as
ordinary types.

class C {}
class C<V> {} // Error, C defined twice
class C<U,V> {} // Error, C defined twice

However, the type lookup rules used during unqualified type name lookup
(§20.9.3) and member access (§20.9.4) do take the number of generic
parameters into account.
=============== =============== =============== =============== =====

The exceptions listed above allow generic types in, for example,
different namespaces to have the same 'simple name' with differing type
parameters. But, since they are in different namespaces they are really
completely unrelated (other than they they happen to share the same
simple name).

I think this is one of the reasons that you find the generic classes in
..NET 2.0 in separate namespaces from their non-generic counterparts.

On the other hand, I don't see the reason why they couldn't allow type
parameters to overload class names, but I'm not a language design
expert, so there's probably a very good reason.

--
mikeb
Nov 16 '05 #6
Justin,
One place I would consider using it, is if I wanted a "performant " Key class
as identified under the Identity Field pattern in Martin Fowler's book
"Patterns of Enterprise Application Architecture".
http://www.martinfowler.com/eaaCatal...tityField.html (you need the book
to see the sample of the Key class).

By "performant " I mean one that is not based on an array of object, as
Martin shows in his book. One that would be based on the actual types of
each key field, plus require the actual number of key fields expected.

Of course there is the expense of defining each key type...

class Key

class Key<T> : Key, IComparable, IComparable<Key <T>> where T :
IComparable<T>

class Key<T1, T2> : Key, IComparable, IComparable<Key <T1, T2>> where T1
: IComparable<T1> where T2 : IComparable<T2>
...

class Key<T1, T2, T3>
...

I would consider defining a base Key type as above that would allow the Key
to be polymorphic with the Layer Super Type.

IComparable<T> is rather cool, one thing I have not figured out is how to
get a non-boxing GetHashCode from a generic...

Just a thought
Jay

Of course I would have constraints on the types, so they implemented
IComparable<Key <T>>
"Justin Shen" <De*******@hotm ail.com> wrote in message
news:es******** ******@TK2MSFTN GP10.phx.gbl...
you can define two class with same name but having different generic
parameters in one assembly. As below:

class Gen<T>
{
}

class Gen<T1,T2>
{
}

any possible use of it?

Nov 16 '05 #7
Additional:
IComparable<T> is rather cool, one thing I have not figured out is how to
get a non-boxing GetHashCode from a generic... C# allows me to call GetHashCode on a generic field, however VB.NET does not
allow me to call GetHashCode, seeing as GetHashCode is (ultimately) Object,
and all generic fields ultimately inherit from Object, I would expect to be
able to call it, I will pursue this in the private Whidbey newsgroups.

Thanks
Jay
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:O7******** ******@TK2MSFTN GP11.phx.gbl... Justin,
One place I would consider using it, is if I wanted a "performant " Key class as identified under the Identity Field pattern in Martin Fowler's book
"Patterns of Enterprise Application Architecture".
http://www.martinfowler.com/eaaCatal...tityField.html (you need the book to see the sample of the Key class).

By "performant " I mean one that is not based on an array of object, as
Martin shows in his book. One that would be based on the actual types of
each key field, plus require the actual number of key fields expected.

Of course there is the expense of defining each key type...

class Key

class Key<T> : Key, IComparable, IComparable<Key <T>> where T :
IComparable<T>

class Key<T1, T2> : Key, IComparable, IComparable<Key <T1, T2>> where T1 : IComparable<T1> where T2 : IComparable<T2>
...

class Key<T1, T2, T3>
...

I would consider defining a base Key type as above that would allow the Key to be polymorphic with the Layer Super Type.

IComparable<T> is rather cool, one thing I have not figured out is how to
get a non-boxing GetHashCode from a generic...

Just a thought
Jay

Of course I would have constraints on the types, so they implemented
IComparable<Key <T>>
"Justin Shen" <De*******@hotm ail.com> wrote in message
news:es******** ******@TK2MSFTN GP10.phx.gbl...
you can define two class with same name but having different generic
parameters in one assembly. As below:

class Gen<T>
{
}

class Gen<T1,T2>
{
}

any possible use of it?


Nov 16 '05 #8
yeah, i am talking about c# 2.0.

and i had tried the code in Whidbey CTP release. It compiles and runs well
so i got the question above. :)
"Jon Skeet [C# MVP]" <sk***@pobox.co m> ????
news:MP******** *************** *@msnews.micros oft.com...
Jiachuan Wang [MSFT] <ji*****@online .microsoft.com> wrote:
class name has to be unique within one namespace. If you have to define two classes with same name, you can put them in different namespaces in one
assembly. C# class does not support template taking parameters like in
C++
I think Justin was actually talking about the generics which will be
available in C# v2.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #9
i had tried the code i listed above in Whidbey CTP release, and the two
class are within the same namespace and even within the same assembly. The
code compiles and i was able to declare two instance of the two class. Hope
it is not a bug and will be removed in the final release. :-p

"mikeb" <ma************ @nospam.mailnul l.com> ????
news:OU******** *****@TK2MSFTNG P11.phx.gbl...
Justin Shen wrote:
you can define two class with same name but having different generic
parameters in one assembly. As below:

class Gen<T>
{
}

class Gen<T1,T2>
{
}

Assuming you're talking about C# 2.0 (Whidbey), are you sure that you
can do this? I haven't played around with Whidbey much, but my reading
of the draft spec indicates that this is not supported (from Section

20.1):
=============== =============== =============== =============== =====
Generic types may not be “overloaded”, that is the identifier of a
generic type must be uniquely named within a scope in the same way as
ordinary types.

class C {}
class C<V> {} // Error, C defined twice
class C<U,V> {} // Error, C defined twice

However, the type lookup rules used during unqualified type name lookup
(§20.9.3) and member access (§20.9.4) do take the number of generic
parameters into account.
=============== =============== =============== =============== =====

The exceptions listed above allow generic types in, for example,
different namespaces to have the same 'simple name' with differing type
parameters. But, since they are in different namespaces they are really
completely unrelated (other than they they happen to share the same
simple name).

I think this is one of the reasons that you find the generic classes in
.NET 2.0 in separate namespaces from their non-generic counterparts.

On the other hand, I don't see the reason why they couldn't allow type
parameters to overload class names, but I'm not a language design
expert, so there's probably a very good reason.

--
mikeb

Nov 16 '05 #10

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

Similar topics

5
4833
by: CoolPint | last post by:
It seems to me that I cannot assign objects of a class which has a constant data member since the data member cannot be changed once the constructor calls are completed. Is this the way it is meant to be? Am I not suppose not to have any constant data member if I am going to have the assignment operator working for the class? Or am I missing something here and there is something I need to learn about? Clear, easy to understand...
8
5689
by: Nick | last post by:
Im trying to insert a bunch of rows into a table. If the row already exists id like to update the row 'counter'. For example... INSERT INTO table1 SELECT field1, field2 FROM table2 ON DUPLICATE KEY UPDATE field2 = 1 Is it possible to use both INSERT... SELECT... with ON DUPLICATE KEY? I cant get it to work.
22
3066
by: Robert Brown | last post by:
suppose I have the following table: CREATE TABLE (int level, color varchar, length int, width int, height int) It has the following rows 1, "RED", 8, 10, 12 2, NULL, NULL, NULL, 20 3, NULL, 9, 82, 25
2
1343
by: shlomi.schwartz | last post by:
Hi all, I'm trying to open a new non rectangular dialog window from an HTA application, is it possible? I tried using window.showModalDialog() with the unadorned feature as a starting point ... but with no luck. My goal is to create a shaped window ... IMPOSSIBLE ?!
3
1137
by: Jiho Han | last post by:
If there is a dll that my asp pages uses but is in a separate assembly, can I define a separate config for it and will it read? For example, if I have a MyLibrary.dll and I define a MyLibrary.dll.config, will objects in MyLibrary.dll have access to the .config? Thanks
11
2188
by: ano | last post by:
Hi, I'm a C# newbie. My application (Solution) contains two Windows application projects. They create their own ".exe" output that means there are 2 Main() methods in one solution. Is is possible to do this? If it's possible, how Project A (A.exe) calls Project B to start (B.exe) application? I can't add a project reference in Project A to call Project B because
9
1401
by: Andy | last post by:
Hi there, I'm trying to do some predicting work over user input, here's my question: for pattern r'match me', the string 'no' will definitely fail to match, but 'ma' still has a chance if user keep on inputting characters after 'ma', so how do I mark 'ma' as a possible match string? Thanks a lot,
2
1079
by: | last post by:
I'd like to make a tool that non-technicians could invoke if there was a defacement or destruction of our database data for whatever reason and an expert wasn't around to tend to things. The sequence would run something like this: 1) Take IIS offline if necessary and drop existing DB connections 2) Back up current database to __dropped.bak 3) Restore from a known good backup 4) put IIS online if necessary
9
3757
by: Cristian | last post by:
algebraic expression 'a*b+c' with CIN .Is it possible? How to transfer the algebraic expression 'a*b+c' to the variable s (all double) with cout in a "Console Application" ? cout<<"Input a,b,c and expression in a,b,c "<<endl; cin>>a; cin>>b; cin>>c;
1
2092
by: robin1983 | last post by:
Dear All, How are you everyone! I need a help from you all. Firstly, I want to know is it possible to fetch the email details from the Outlook to Excel or Database by using PHP. MS outlook has his own feature to export the details. But, by this its not possible to extract the body of the mail. Here, I want to know, is it possible to fetch mail details like sender email, sender date, received date, subject, body of the mail etc and save in...
0
9423
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,...
0
10216
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
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
6675
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
5309
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
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

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.