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.
精彩评论