可能的编译器错误(C#3.0) [英] Possible Compiler Bug (C# 3.0)

查看:68
本文介绍了可能的编译器错误(C#3.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

附加程序无法编译。错误消息说:

"名为''i'的局部变量不能在此范围内声明,因为它会给'i'赋予不同的含义',已经在''孩子'中使用了'

范围来表示别的东西

- 这没有多大意义。这是一个编译错误吗?

TJ


class program

{

static void Main( string [] args)

{

switch(0){

case 0:

for(int i = 0 ;;){

}

案例1:

//错误CS0136:名为我的局部变量不能是在这个范围内声明了

,因为它会给''i'赋予不同的含义,这已经在''子'范围内使用了
来表示别的东西

int i = 0;

}

}

}

解决方案



" Tomasz J" < oe **** @ nospam.nospamwrote in message

news:eg ************** @ TK2MSFTNGP06.phx.gbl ...


附加程序无法编译。错误消息说:

"名为''i'的局部变量不能在此范围内声明,因为它会给'i'赋予不同的含义',已经在''孩子'中使用了'

范围来表示别的东西

- 这没有多大意义。这是一个编译错误吗?

TJ


class program

{

static void Main( string [] args)

{

switch(0){

case 0:

for(int i = 0 ;;){

}

案例1:



Console.Writeline(i.ToString( ));

//如果以上编译,则显示i值,那就是

IN_SCOPE并已经宣布。


// int i = 0;

}

}

}



e-gads!我以为x,y,z,j,k,我的日子已经死了,走了。我们应该将这种风格称为复古代码吗? ;-)


" Tomasz J" < oe **** @ nospam.nospamwrote in message

news:eg ************** @ TK2MSFTNGP06.phx.gbl ...


附加程序无法编译。错误消息说:

"名为''i'的局部变量不能在此范围内声明,因为它会给'i'赋予不同的含义',已经在''孩子'中使用了'

范围来表示别的东西

- 这没有多大意义。这是一个编译错误吗?

TJ


class program

{

static void Main( string [] args)

{

switch(0){

case 0:

for(int i = 0 ;;){

}

案例1:

//错误CS0136:名为我的局部变量不能是在这个范围内声明了

,因为它会给''i'赋予不同的含义,这已经在''子'范围内使用了
来表示别的东西

int i = 0;

}

}

}


这不是一个bug,在switch块中定义的变量范围是

整个开关块。我想,这是为了帮助那些使用goto

案例或转到默认功能的人。

了解更多信息:
http://msdn.microsoft.com/en- us / libr ... 49(VS.71).aspx


-

Ciaran O''''Donnell http://wannabedeveloper.spaces.live.com

Tomasz J写道:


附加程序无法编译。错误消息说:

"名为''i'的局部变量不能在此范围内声明,因为它会给'i'赋予不同的含义',已经在''孩子'中使用了'

范围来表示别的东西

- 这没有多大意义。这是一个编译错误吗?

TJ


class program

{

static void Main( string [] args)

{

switch(0){

case 0:

for(int i = 0 ;;){

}

案例1:

//错误CS0136:名为我的局部变量不能是在这个范围内声明了

,因为它会给''i'赋予不同的含义,这已经在''子'范围内使用了
来表示别的东西

int i = 0;

}

}

}


The attached program does not compile. The error message says:
"A local variable named ''i'' cannot be declared in this scope because it
would give a different meaning to ''i'', which is already used in a ''child''
scope to denote something else"
- which does not make much sense. Is it a compiles bug?
TJ

class Program
{
static void Main(string[] args)
{
switch (0) {
case 0:
for (int i = 0; ; ) {
}
case 1:
// error CS0136: A local variable named ''i'' cannot be declared
in this scope because it would give a different meaning to ''i'', which is
already used in a ''child'' scope to denote something else
int i = 0;
}
}
}

解决方案


"Tomasz J" <oe****@nospam.nospamwrote in message
news:eg**************@TK2MSFTNGP06.phx.gbl...

The attached program does not compile. The error message says:
"A local variable named ''i'' cannot be declared in this scope because it
would give a different meaning to ''i'', which is already used in a ''child''
scope to denote something else"
- which does not make much sense. Is it a compiles bug?
TJ

class Program
{
static void Main(string[] args)
{
switch (0) {
case 0:
for (int i = 0; ; ) {
}
case 1:

Console.Writeline( i.ToString());
//if the above compiles, and it shows the "i" value, then it is
IN_SCOPE and already declared.

//int i = 0;
}
}
}



e-gads ! I thought the days of x,y,z,j,k,i were dead and gone. Should we
call this style ''retro-code''? ;-)

"Tomasz J" <oe****@nospam.nospamwrote in message
news:eg**************@TK2MSFTNGP06.phx.gbl...

The attached program does not compile. The error message says:
"A local variable named ''i'' cannot be declared in this scope because it
would give a different meaning to ''i'', which is already used in a ''child''
scope to denote something else"
- which does not make much sense. Is it a compiles bug?
TJ

class Program
{
static void Main(string[] args)
{
switch (0) {
case 0:
for (int i = 0; ; ) {
}
case 1:
// error CS0136: A local variable named ''i'' cannot be declared
in this scope because it would give a different meaning to ''i'', which is
already used in a ''child'' scope to denote something else
int i = 0;
}
}
}


This is not a bug, the scope of a variable define in a switch block is the
entire switch block. This is, i supposed, to help people who use the goto
case or goto default functionality.
for more information have a look at:
http://msdn.microsoft.com/en-us/libr...49(VS.71).aspx

--
Ciaran O''''Donnell
http://wannabedeveloper.spaces.live.com
"Tomasz J" wrote:

The attached program does not compile. The error message says:
"A local variable named ''i'' cannot be declared in this scope because it
would give a different meaning to ''i'', which is already used in a ''child''
scope to denote something else"
- which does not make much sense. Is it a compiles bug?
TJ

class Program
{
static void Main(string[] args)
{
switch (0) {
case 0:
for (int i = 0; ; ) {
}
case 1:
// error CS0136: A local variable named ''i'' cannot be declared
in this scope because it would give a different meaning to ''i'', which is
already used in a ''child'' scope to denote something else
int i = 0;
}
}
}


这篇关于可能的编译器错误(C#3.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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