C#2.0规范中的错误? [英] Errors in C# 2.0 specification?

查看:77
本文介绍了C#2.0规范中的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我猜C#2.0规范的当前版本有很多错误。

让我们看看很多例子中的一个(我使用C#Express beta 2,但认为你可以使用

任何C#2.0编译器)。所以,在文件
http://download.microsoft.com/downlo...cationver2.doc

的20.1.8泛型类中的重载部分任何人都可以阅读:

....

以下示例显示根据此规则

有效且无效的重载:

interface I1< T> {...}

interface I2< T> {...}

class G1< U>

{

long F1(U u); //无效重载,G< int>将有两个

int F1(int i); //具有相同签名的成员

void F2(U u1,U u2); //有效重载,没有类型参数U

void F2(int i,string s); //可以同时为int和string

void F3(I1< U> a); //有效超载

void F3(I2< U> a);

void F4(U a); //有效超载

无效F4(U [] a);

}

类G2< U,V>

{

无效F5(U u,V v); //无效的重载,G2< int,int>将会有

无效F5(V v,U u); //两个具有相同签名的成员

void F6(U u,I1< V> v); //无效重载,G2< I1< int>,int>将

无效F6(I1< V> v,U u); //有两个具有相同签名的成员

void F7(U u1,I1< V> v2); //有效过载,U不能是V和I1< V>

void F7(V v1,U u2); //同时

void F8(ref U u); //无效超载

无效F8(超出V v);

}

类C1 {...}

class C2 {...}

class G3< U,V>其中U:C1其中V:C2

{

void F9(U u); //无效的过载,对U和V的约束

void F9(V v); //检查过载时会被忽略

}


好​​吧,让我们只选C2级和I1接口

接口I1< T> {...}

....

class G2< U,V>

{

void F5(U u,V v); //无效的重载,G2< int,int>将会有

无效F5(V v,U u); //两个具有相同签名的成员

void F6(U u,I1< V> v); //无效重载,G2< I1< int>,int>将

无效F6(I1< V> v,U u); //有两个具有相同签名的成员

void F7(U u1,I1< V> v2); //有效过载,U不能是V和I1< V>

void F7(V v1,U u2); //同时

void F8(ref U u); //无效过载

无效F8(输出V v);

}

并分析其评论:

void F5(U u,V v); //无效的重载,G2< int,int>将会有

无效F5(V v,U u); //两个具有相同签名的成员

/ * /

正确,但只有我们创建类似G2< int,int>的东西如果我们尝试调用F5,那么(完全是AND,

只是创建G2< int,int>的事实)。如果我们创建

G2< int,long>并调用g2instance.F5((长)4,8)都没关系。

结论:半错误。在大多数情况下,这种过载是有效的。


void F6(U u,I1< V> v); //无效重载,G2< I1< int>,int>将

无效F6(I1< V> v,U u); //有两个具有相同签名的成员

/ * /

不正确,I1< int>和int是不同的类型,它们在从左到右的顺序中占据不同的
位置。在参数列表中。

结论:错误。这是100%有效的过载。


void F7(U u1,I1< V> v2); //有效过载,U不能是V和I1< V>

void F7(V v1,U u2); //同时

/ * /

结论:绝对正确。这是100%有效的超载


void F8(ref U u); //无效过载

无效F8(输出V v);

/ * /

不正确,ref和out修饰符是a的一部分方法的签名

结论:错误。这是100%有效的超载。


总计:4个断言,3个错误!!我是对的吗?

I guess there are many errors in current version of C# 2.0 specification.
Let''s see one of many examples(I use C# Express beta 2, but think you can use
any C#2.0 compiler). So, in document
http://download.microsoft.com/downlo...cationver2.doc
in section "20.1.8 Overloading in generic classes" anyone can read:
....
The following examples show overloads that are valid and invalid according
to this rule:
interface I1<T> {...}
interface I2<T> {...}
class G1<U>
{
long F1(U u); // Invalid overload, G<int> would have two
int F1(int i); // members with the same signature
void F2(U u1, U u2); // Valid overload, no type argument for U
void F2(int i, string s); // could be int and string simultaneously
void F3(I1<U> a); // Valid overload
void F3(I2<U> a);
void F4(U a); // Valid overload
void F4(U[] a);
}
class G2<U,V>
{
void F5(U u, V v); // Invalid overload, G2<int,int> would have
void F5(V v, U u); // two members with the same signature
void F6(U u, I1<V> v); // Invalid overload, G2<I1<int>,int> would
void F6(I1<V> v, U u); // have two members with the same signature
void F7(U u1, I1<V> v2); // Valid overload, U cannot be V and I1<V>
void F7(V v1, U u2); // simultaneously
void F8(ref U u); // Invalid overload
void F8(out V v);
}
class C1 {...}
class C2 {...}
class G3<U,V> where U: C1 where V: C2
{
void F9(U u); // Invalid overload, constraints on U and V
void F9(V v); // are ignored when checking overloads
}

Ok, let''s take class G2 and interface I1 only
interface I1<T> {...}
....
class G2<U,V>
{
void F5(U u, V v); // Invalid overload, G2<int,int> would have
void F5(V v, U u); // two members with the same signature
void F6(U u, I1<V> v); // Invalid overload, G2<I1<int>,int> would
void F6(I1<V> v, U u); // have two members with the same signature
void F7(U u1, I1<V> v2); // Valid overload, U cannot be V and I1<V>
void F7(V v1, U u2); // simultaneously
void F8(ref U u); // Invalid overload
void F8(out V v);
}
and analyze its comments:
void F5(U u, V v); // Invalid overload, G2<int,int> would have
void F5(V v, U u); // two members with the same signature
/*/
Correct, but ONLY if we create something like G2<int,int> AND(exactly AND,
just fact of creating G2<int,int> is OK) if we try call F5. If we create
G2<int, long> and call g2instance.F5((long)4, 8) all fine.
Conclusion: semi-error. In most cases this overload IS valid.

void F6(U u, I1<V> v); // Invalid overload, G2<I1<int>,int> would
void F6(I1<V> v, U u); // have two members with the same signature
/*/
Incorrect, I1<int> and int are different types and they occupy different
positions in "left-to-right-order" within parameters-list.
Conclusion: Error. This is 100% valid overload.

void F7(U u1, I1<V> v2);// Valid overload, U cannot be V and I1<V>
void F7(V v1, U u2); // simultaneously
/*/
Conclusion: Absolutely correct. This is 100% valid overload

void F8(ref U u); // Invalid overload
void F8(out V v);
/*/
Incorrect, the ref and out modifiers ARE PART of a method''s signature
Conclusion: Error. This is 100% valid overload.

Grand total: 4 assertions, 3 errors!! Am I right?

推荐答案



" Smarty" <钐**** @ discussions.microsoft.com>在留言中写道

新闻:7F ********************************** @ microsof t.com ...

"Smarty" <Sm****@discussions.microsoft.com> wrote in message
news:7F**********************************@microsof t.com...
我想当前版本的C#2.0规范中有很多错误。
让我们看看很多例子中的一个(我使用C#Express beta 2,但是认为你可以使用任何C#2.0编译器。所以,在文件
http://download.microsoft.com/downlo...cationver2.doc
在20.1.8泛型类中的重载部分中任何人都可以阅读:
...
I guess there are many errors in current version of C# 2.0 specification.
Let''s see one of many examples(I use C# Express beta 2, but think you can
use
any C#2.0 compiler). So, in document
http://download.microsoft.com/downlo...cationver2.doc
in section "20.1.8 Overloading in generic classes" anyone can read:
...



你参考规范的旧草稿,你把问题发布在另一个

线程但是你选择了错误的答案并下载了

规格的旧草稿。

另请注意此NG仅适用于已发布的产品,您应该发布v2.0 beta

问题/问题到whidbey论坛 http://forums.microsoft.com/ msdn /

如果你认为你发现了一个错误(产品,文档等...)你应该提交一个问题

http://lab.msdn.microsoft.com/produc...k/default.aspx


Willy。


You refer to an old draft of the specs, you posted the question on another
thread but you picked the wrong answer and downloaded an old draft of the
specification.
Also note this NG is for released products only, You should post v2.0 beta
questions/issues to the whidbey forums http://forums.microsoft.com/msdn/ and
if you think you found a bug (product, docs etc...) you should file an issue
to http://lab.msdn.microsoft.com/produc...k/default.aspx.

Willy.


> G2类< U,V>
> class G2<U,V>
{
void F5(U u,V v); //无效的重载,G2< int,int>会有空的F5(V v,你); //具有相同签名的两个成员
void F6(U u,I1< V> v); //无效重载,G2< I1< int>,int>会使F6无效(I1< V> v,U u); //有两个具有相同签名的成员
void F7(U u1,I1< V> v2); //有效过载,U不能是V和I1< V>
void F7(V v1,U u2); //同时
void F8(ref U u); //无效过载
void F8(out V v);
}
并分析其评论:
void F5(U u,V v); //无效的重载,G2< int,int>会有空的F5(V v,你); //具有相同签名的两个成员
/ * /
正确,但只有我们创建类似G2< int,int>的东西如果我们尝试调用F5,则(完全是AND,
只是创建G2< int,int>的事实)。如果我们创建
G2< int,long>并调用g2instance.F5((长)4,8)都没关系。
结论:半错误。在大多数情况下,这种过载是有效的。


很抱歉,但是如果出现无效的情况,则超载

无效。这是正确的。

void F6(U u,I1< V> v); //无效重载,G2< I1< int>,int>会使F6无效(I1< V> v,U u); //有两个具有相同签名的成员
/ * /
不正确,I1< int>和int是不同的类型,它们在从左到右中占据不同的位置。在参数列表中。
结论:错误。这是100%有效的过载。


再次错误。你读这篇文章时犯了一个错误。考虑G2< I1< int>,

int>再次注意,你导致

void F6(I1< int>,I1< int>)for void F6(U u,I1< V> v)



void F6(I1< int>,I1< int>)for void F6(I1< V>,U u);


,因为U是I1< INT>和V是int

void F8(ref U u); //无效的重载
void F8(输出V v);
/ * /
不正确,ref和out修饰符是方法签名的一部分
结论:错误。这是100%有效的超载。
{
void F5(U u, V v); // Invalid overload, G2<int,int> would have
void F5(V v, U u); // two members with the same signature
void F6(U u, I1<V> v); // Invalid overload, G2<I1<int>,int> would
void F6(I1<V> v, U u); // have two members with the same signature
void F7(U u1, I1<V> v2); // Valid overload, U cannot be V and I1<V>
void F7(V v1, U u2); // simultaneously
void F8(ref U u); // Invalid overload
void F8(out V v);
}
and analyze its comments:
void F5(U u, V v); // Invalid overload, G2<int,int> would have
void F5(V v, U u); // two members with the same signature
/*/
Correct, but ONLY if we create something like G2<int,int> AND(exactly AND,
just fact of creating G2<int,int> is OK) if we try call F5. If we create
G2<int, long> and call g2instance.F5((long)4, 8) all fine.
Conclusion: semi-error. In most cases this overload IS valid.

Sorry, but if one situation comes up where it is not valid, the overload
cannot be valid. This is correct.
void F6(U u, I1<V> v); // Invalid overload, G2<I1<int>,int> would
void F6(I1<V> v, U u); // have two members with the same signature
/*/
Incorrect, I1<int> and int are different types and they occupy different
positions in "left-to-right-order" within parameters-list.
Conclusion: Error. This is 100% valid overload.
Incorrect again. You made a mistake in reading this. Consider G2<I1<int>,
int> again, notice that you result in
void F6(I1<int>,I1<int>) for void F6(U u, I1<V> v)
and
void F6(I1<int>,I1<int>) for for void F6(I1<V>, U u);

as U is I1<int> and V is int

void F8(ref U u); // Invalid overload
void F8(out V v);
/*/
Incorrect, the ref and out modifiers ARE PART of a method''s signature
Conclusion: Error. This is 100% valid overload.




实际上,这种语言在任何情况下都不允许这样做,所以它不是有效的。它的脸。 ref和out在

CLR级别生成相同的方法签名,其中ref或out由属性标记。



Actually, the language doesn''t permit that in any circumstance, so its not
valid on its face. ref and out generate identical method signatures at the
CLR level, with ref or out one being marked by an attribute.




" Willy Denoyette [MVP]"写道:

"Willy Denoyette [MVP]" wrote:

您参考规范的旧草稿,您在另一个
帖子上发布了问题,但您选择了错误的答案并下载了旧的草稿
规范。
另请注意,此NG仅适用于已发布的产品,您应将v2.0 beta版/问题发布到whidbey论坛 http://forums.microsoft.com/msdn/
如果你认为你发现了一个bug(产品,文档等...)您应该向提交问题
http://lab.msdn.microsoft.com/produc...k/default.aspx


Willy。

You refer to an old draft of the specs, you posted the question on another
thread but you picked the wrong answer and downloaded an old draft of the
specification.
Also note this NG is for released products only, You should post v2.0 beta
questions/issues to the whidbey forums http://forums.microsoft.com/msdn/ and
if you think you found a bug (product, docs etc...) you should file an issue
to http://lab.msdn.microsoft.com/produc...k/default.aspx.

Willy.



好​​的,谢谢。我会尝试这种方法。


OK, thanks. I will try this approach.


这篇关于C#2.0规范中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆