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

C# 2.0 spec: generics and invalid overloads

According to the C# 2.0 draft spec, the following should not compile:

class G1<U>
{
long F1(U u) {return 0;} // Invalid overload, G<int> would have two
int F1(int i){return 1;} // members with the same signature
}

However, it compiles without error or warning for me. This also compiles
clean:

class G1<U>
{
int F1(U u) {return 0;} // Invalid overload, G<int> would have two
int F1(int i){return 1;} // members with the same signature
}

Did the spec change on this? Is this now allowed? The version of the
spec that I downloaded was from May 2004.

FWIW, compiler version is
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727

H^2

Mar 28 '06 #1
2 1212
Harold Howe wrote:
According to the C# 2.0 draft spec, the following should not compile:

class G1<U>
{
long F1(U u) {return 0;} // Invalid overload, G<int> would have two
int F1(int i){return 1;} // members with the same signature
}

However, it compiles without error or warning for me. This also compiles
clean:

class G1<U>
{
int F1(U u) {return 0;} // Invalid overload, G<int> would have two
int F1(int i){return 1;} // members with the same signature
}

Did the spec change on this? Is this now allowed? The version of the
spec that I downloaded was from May 2004.

FWIW, compiler version is
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727


See section 20.1.8 of the currrent C# language specification 2.0 in the
March 2005 draft available from
http://download.microsoft.com/downlo...cification.doc.
Basically it is valid and will be resolved to the non-generic overload of
the method.
--
Tom Porterfield

Mar 28 '06 #2
See section 20.1.8 of the currrent C# language specification 2.0 in the
March 2005 draft available from
http://download.microsoft.com/downlo...cification.doc.


That is exactly what I needed. Thank you very much.

H^2
Mar 28 '06 #3

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

Similar topics

2
by: Wiktor Zychla | last post by:
I've read several documents about upcoming C# generics and I still cannot understand one thing. Would it be valid to write a code like this: class SomeClass { public void AMethod<T>(T a, T...
13
by: Anders Borum | last post by:
Hello! Now that generics are introduces with the next version of C#, I was wondering what kind of performance gains we're going to see, when switching from e.g. the general hashtable to a...
17
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...
16
by: bigtexan | last post by:
I would like to do the following and cannot figure it out. public class A<T> { public delegate T GetValueDelegate(A<T> var); public GetValueDelegate GetValue = new GetValueDelegate(B.GetValue);...
2
by: Marco Segurini | last post by:
Hi, The following code shows my problem: using System; using System.Collections.Generic; using System.Text; ....
13
by: Luc Vaillant | last post by:
I try to compare to values of generic value type T in a generic class as follow: public class C<T> where T : struct { private T value1; private T value2; C(T value1, T value2) {
5
by: teel | last post by:
Hi there, I'm trying to apply "less than" and "more than" operators on the Generics (class template-like) type objects. Below is the code of my class representing a parameter that can be any type,...
17
by: My interest | last post by:
How can I use * operator in C# generics? e.g. class foo<T_> { T_ v1, v2: public T_ squar() { return v1 * v2; /// wrong! }
14
by: Tony | last post by:
Hello! It says "Another limitation that you need to be aware of is that using the operator == and != are only permitted when comparing a value of a type supplied to a generic type to null....
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
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,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.