开发者

Why can't variables of different type be named the same?

I know the below i开发者_如何学编程s illegal in the same code block in C# but is there any possible way around it apart from the obvious (naming them differently) ?

    string test;
    int test; 


Ambiguity

Ok, let's assume that is valid and you can do

string test = "Hallo";
int test = 1;

should

test.ToString();

result in "Hallo" or in "1"?

It would just not be possible for the compiler to know what object you are refering to in some circumstances as you can see. I hope this answers your question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜