真奇怪5线范围相关的问题 [英] Really weird 5 line scope-related problem
问题描述
这有什么问题?
class Example1
{
public static long myClassVar;
public static void Main()
{
{
long myClassVar = 5;
}
myClassVar = 36;
}
}
它不会编译。 ....为什么?我不需要修复但我很困惑
为什么这不会编译。
它在myClassVar = 36时出错与声明冲突
Example1.myClassVar
谢谢
Afzal
What is wrong with this?
class Example1
{
public static long myClassVar;
public static void Main()
{
{
long myClassVar = 5;
}
myClassVar = 36;
}
}
It will not compile.....why? I do not need a "fix" but rather am confused
why this will not compile.
It gives an error at myClassVar=36 that is conflicts with declaration
Example1.myClassVar
Thanks
Afzal
推荐答案
" Afzal马兹哈尔" < AF *** @ mazhar.net>在消息中写道
news:fO ********************** @ news4.srv.hcvlny.cv。 net ...
"Afzal Mazhar" <af***@mazhar.net> wrote in message
news:fO**********************@news4.srv.hcvlny.cv. net...
这有什么问题?
类Example1
{public static long myClassVar;
public static void Main()
{
{m> myClassVar = 5;
}
myClassVar = 36;
}
}
它不会编译.....为什么?我不需要修复但我很困惑
为什么这不会编译。
它在myClassVar = 36时出错与声明冲突
Example1.myClassVar
What is wrong with this?
class Example1
{
public static long myClassVar;
public static void Main()
{
{
long myClassVar = 5;
}
myClassVar = 36;
}
}
It will not compile.....why? I do not need a "fix" but rather am confused
why this will not compile.
It gives an error at myClassVar=36 that is conflicts with declaration
Example1.myClassVar
Hi Afzal,
编译器将myClassVar标识符解析为命名空间
Example1.myClassVar并正在寻找一个名为myClassVar的类,
没有。您不应将名称空间标识符命名为类型
或类型成员。相反,使用
Company.Product.SubSystem.Library作为使用
命名空间时的一般准则。
Joe
-
http://www.csharp-station .com
" Afzal Mazhar" < AF *** @ mazhar.net>在消息中写道
news:fO ********************** @ news4.srv.hcvlny.cv。 net ...
"Afzal Mazhar" <af***@mazhar.net> wrote in message
news:fO**********************@news4.srv.hcvlny.cv. net...
这有什么问题?
类Example1
{public static long myClassVar;
public static void Main()
{
{m> myClassVar = 5;
}
myClassVar = 36;
}
}
它不会编译.....为什么?我不需要修复但我很困惑
为什么这不会编译。
它在myClassVar = 36时出错与声明冲突
Example1.myClassVar
What is wrong with this?
class Example1
{
public static long myClassVar;
public static void Main()
{
{
long myClassVar = 5;
}
myClassVar = 36;
}
}
It will not compile.....why? I do not need a "fix" but rather am confused
why this will not compile.
It gives an error at myClassVar=36 that is conflicts with declaration
Example1.myClassVar
Hi Afzal,
编译器将myClassVar标识符解析为命名空间
Example1.myClassVar并正在寻找一个名为myClassVar的类,
没有。您不应将名称空间标识符命名为类型
或类型成员。相反,使用
Company.Product.SubSystem.Library作为使用
命名空间时的一般准则。
Joe
-
http://www.csharp-station .com
" Afzal Mazhar" < AF *** @ mazhar.net>写在
新闻:fO ********************** @ news4.srv.hcvlny.cv。 net:
"Afzal Mazhar" <af***@mazhar.net> wrote in
news:fO**********************@news4.srv.hcvlny.cv. net:
这有什么问题?
类Example1
{public static long myClassVar;
public static void Main()
{
{m> myClassVar = 5;
}
myClassVar = 36;
}
}
它不会编译.....为什么?我不需要修复但是我很困惑为什么这不会编译。
它在myClassVar = 36时出错与
声明相矛盾Example1.myClassVar
What is wrong with this?
class Example1
{
public static long myClassVar;
public static void Main()
{
{
long myClassVar = 5;
}
myClassVar = 36;
}
}
It will not compile.....why? I do not need a "fix" but rather am
confused why this will not compile.
It gives an error at myClassVar=36 that is conflicts with
declaration Example1.myClassVar
Afzal,
错误CS0135的文档说明:
< QUOTE>
编译器不允许隐藏名称,这通常会导致代码中的逻辑错误。
以下示例生成CS0135:
// CS0135 .cs
公共类MyClass2
{
public static int i = 0;
public static void Main()
{
{
int i = 4;
i ++;
}
i = 0; // CS0135
}
}
< / QUOTE>
希望这会有所帮助。
克里斯。
-------------
CR Timmons Consulting,Inc。
< a rel =nofollowhref =http://www.crtimmonsinc.com/target =_ blank> http://www.crtimmonsinc.com/
这篇关于真奇怪5线范围相关的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!