开发者

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

开发者 https://www.devze.com 2023-04-12 03:29 出处:网络
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) ?

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

精彩评论

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