new和operator ++ [英] new and operator ++
问题描述
我有一个类型:
public struct Value
{
public static Value operator ++(Value v)
{
返回新值();
}
public static Value New()
{
返回新值();
}
}
此代码
价值v1 = Value.New()++;
编译成功,但我得到InvalidProgramException。
相同的
值v = new Value()++;
从struct更改为class无济于事。
Microsoft(R)Visual C#2005编译器版本8.00.50727.42
Win XP SP2。
这很有意思,因为我得到同样的东西(而且会/>
假设C#编译器不会生成无效代码。
我会将此作为错误提交给Microsoft Connect。
-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse .com
" Kerneltrap" < Sh ****** @ gmail.com写信息
新闻:11 ********************* @ q69g2000hsb。 googlegro ups.com ...
我有一个类型:
public struct Value
{
public static Value operator ++(Value v)
{
返回新值();
}
公共静态值新()
{
返回新值();
}
}
此代码
值v1 = Value.New()++;
编译成功,但我得到InvalidProgramException。
同样的
值v =新值()++;
从struct更改为class无济于事。
Microsoft(R)Visual C#2005编译器版本8.00.50727.42
Win XP SP2。
Kerneltrap写道:
我有一个类型:
public struct Value
{
public static Value operator ++(Value v)
{
返回新值();
}
public static Value New()
{
返回新值();
}
}
此代码
值v1 = Value.New()++;
编译成功,但我得到InvalidProgramException。
相同的
值v = new Value()++;
从struct更改为class无济于事。
Microsoft(R)Visual C#2005编译器版本8.00.50727.42
Win XP SP2。
嗨
JOOI,Mono C#编译器产生编译错误:
"错误CS0131:作业的左侧必须是变量,
属性或索引器
有趣。
-
Tom Spink
爱丁堡大学
"汤姆斯宾克 < ts **** @ gmail.com写信息
新闻:%2 *************** @ TK2MSFTNGP02.phx.gbl ...
Kerneltrap写道:
>
我有一个类型:
public struct Value
{public static Value operator ++(Value v)
{
返回新值();
公共静态值新()
{
返回新值();
}
}
此代码
值v1 = Value.New()++;
编译成功,但我得到InvalidProgramException。
同样的
值v = new Value()++;
从struct更改为class无济于事。
Microsoft(R)Visual C#2005编译器版本8.00.50727.42
Win XP SP2。
嗨
JOOI,Mono C#编译器产生编译错误:
"错误CS0131:作业的左侧必须是变量,
属性或索引器
有趣。
-
Tom Spink
爱丁堡大学
这实际上是C#编译器应该做的,这是一个编译器
错误,在Orcas版本的编译器中得到了纠正。
威利。
Hi,
I have a type:
public struct Value
{
public static Value operator ++(Value v)
{
return new Value();
}
public static Value New()
{
return new Value();
}
}
This code
Value v1 = Value.New()++;
compiles successfully, but i get InvalidProgramException.
The same for
Value v = new Value()++;
Changing from struct to class doesn''t help.
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
Win XP SP2.
解决方案This is pretty interesting, as I get the same thing (and one would
assume that the C# compiler wouldn''t produce invalid code).
I would submit this to Microsoft Connect as a bug.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Kerneltrap" <Sh******@gmail.comwrote in message
news:11*********************@q69g2000hsb.googlegro ups.com...Hi,
I have a type:
public struct Value
{
public static Value operator ++(Value v)
{
return new Value();
}
public static Value New()
{
return new Value();
}
}
This code
Value v1 = Value.New()++;
compiles successfully, but i get InvalidProgramException.
The same for
Value v = new Value()++;
Changing from struct to class doesn''t help.
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
Win XP SP2.
Kerneltrap wrote:
Hi,
I have a type:
public struct Value
{
public static Value operator ++(Value v)
{
return new Value();
}
public static Value New()
{
return new Value();
}
}
This code
Value v1 = Value.New()++;
compiles successfully, but i get InvalidProgramException.
The same for
Value v = new Value()++;
Changing from struct to class doesn''t help.
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
Win XP SP2.Hi
JOOI, the Mono C# Compiler yields a compilation error:
"error CS0131: The left-hand side of an assignment must be a variable, a
property or an indexer"
Interesting.
--
Tom Spink
University of Edinburgh
"Tom Spink" <ts****@gmail.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...Kerneltrap wrote:
>Hi,
I have a type:
public struct Value
{
public static Value operator ++(Value v)
{
return new Value();
}
public static Value New()
{
return new Value();
}
}
This code
Value v1 = Value.New()++;
compiles successfully, but i get InvalidProgramException.
The same for
Value v = new Value()++;
Changing from struct to class doesn''t help.
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
Win XP SP2.
Hi
JOOI, the Mono C# Compiler yields a compilation error:
"error CS0131: The left-hand side of an assignment must be a variable, a
property or an indexer"
Interesting.
--
Tom Spink
University of Edinburgh
This is actually what the C# compiler should do as well, this is a compiler
error that is corrected in Orcas version of the compiler.
Willy.
这篇关于new和operator ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!