Hi,
[Section 20.1 The C# Programming Language;Anders Hejlsberg, Scott
Wiltamuth, Peter Golde]
"
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
"
But I was unable to verify this using Microsoft Visual C# 2005, which
reports no error:
class Program
{
class C { }
class C<V{ } // no error reported
class C<U, V{ } // no error reported
static void Main(string[] args)
{
}
}
Is this an error in the book or something else?
Thanks!
Mulugeta. 3 1365
"muler" <mu*************@gmail.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
Hi,
[Section 20.1 The C# Programming Language;Anders Hejlsberg, Scott
Wiltamuth, Peter Golde]
"
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
"
But I was unable to verify this using Microsoft Visual C# 2005, which
reports no error:
class Program
{
class C { }
class C<V{ } // no error reported
class C<U, V{ } // no error reported
static void Main(string[] args)
{
}
}
Is this an error in the book or something else?
Looks like an error in the book. While C++ templates support default
arguments, generics do not, so differing numbers of generic parameters can
give you the same result. This is allowed because the number of generic
arguments is part of the mangled name (List`1, Dictionary`2 for instance).
However, you still cannot overload generics. For example, I believe the
following will not compile:
class C<U, Vwhere U : List<V{}
class C<U, Vwhere U : LinkedList<V{}
>
Thanks!
Mulugeta.
muler <mu*************@gmail.comwrote:
[Section 20.1 The C# Programming Language;Anders Hejlsberg, Scott
Wiltamuth, Peter Golde]
"
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
"
I believe that book came out before VS2005 (in fact I'm sure it did - I
got a copy in September 2005), and I believe the language spec changed
a little bit after that. Here's the relevant section from the ECMA spec
(freely downloadable):
<quote>
Generic types can be =3Foverloaded=3F on the number of type parameters;
that is two type declarations within the same namespace or outer type
declaration can use the same identifier as long as they have a
different number of type parameters.
class C {}
class C<V{} // OK
struct C<U,V{} // OK
class C<A,B{} // Error, C with two type parameters defined twice
</quote>
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
On Apr 20, 9:18 pm, Jon Skeet [C# MVP] <s...@pobox.comwrote:
muler <mulugeta.abe...@gmail.comwrote:
[Section 20.1 The C# Programming Language;Anders Hejlsberg, Scott
Wiltamuth, Peter Golde]
"
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
"
I believe that book came out before VS2005 (in fact I'm sure it did - I
got a copy in September 2005), and I believe the language spec changed
a little bit after that. Here's the relevant section from the ECMA spec
(freely downloadable):
<quote>
Generic types can be =3Foverloaded=3F on the number of type parameters;
that is two type declarations within the same namespace or outer type
declaration can use the same identifier as long as they have a
different number of type parameters.
class C {}
class C<V{} // OK
struct C<U,V{} // OK
class C<A,B{} // Error, C with two type parameters defined twice
</quote>
--
Jon Skeet - <s...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Thanks! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andreas Huber |
last post by:
What follows is a discussion of my experience with .NET generics & the
..NET framework (as implemented in the Visual Studio 2005 Beta 1),
which leads to questions as to why certain things are the...
|
by: Tom Jastrzebski |
last post by:
Hello everybody,
Here is the problem I came across experimenting with Generics.
I would like to write a class or a struct adding integer to any other,
initially undefined *numeric type*.
So, my...
|
by: Urs Eichmann |
last post by:
While experimenting with the Feb CTP Edition of VB 2005, I came across
"generic procedures". You can write:
Public Class Foo
Public Sub MySub(Of tDisp As IDisposable)(ByVal vMyParm As Integer)...
|
by: Wiktor Zychla [C# MVP] |
last post by:
it is obvious that you cannot have two methods that differ only on
returning value:
void F() { }
int F() { }
it is however interesting (and to me : surprizing) that this restriction
also...
|
by: steve yee |
last post by:
i think c should adapt c++ template standard, as well as namespace. if
so, c can replace c++ in many cases.
|
by: BombDrop |
last post by:
I'm working on a system that has 4 different types of client they
have mostly the same attributes so I decided to create an interface
IClient for them to implement and then just add the differing...
|
by: phancey |
last post by:
I'm quite new to generics. I have 2 generic classes:
MyClass<Tand MyOtherClass<T>.
MyClass<Thas 2 public Add methods
Add(MyOtherClass<T>);
Add(MyOtherClass<Wrapper<T>>); (Wrapper<Tis another...
|
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= |
last post by:
Hi,
I have written a generic method which does different things depending on
the type of the parameter. I got it to work, but it seems really inelegant.
Is there a better way to do this?
In the...
|
by: tadmill |
last post by:
Is it possible to pass a generic parameter of the same class to to its
constructor, where the "T" type passed in the constructor is different
than the "T" type of the instanced class?
ie,
...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
| |