c# - Casting null doesn't compile -



c# - Casting null doesn't compile -

accidentally @ work wrote next line of code:

string x = (object) null; // var x = (object)null , changed var string instead of // object x = null;

this gave me compilation error similar this: can't cast source type object target type string

why? isn't null bunch of zeros pointing "nowhere" memory address, no matter type is?

the question here "why compiler not take business relationship fact knows assigned value constant reference known null?"

the reply is: why should it? what's compelling benefit of taking info account? deliberately said "i want look treated though of type object", , can't assign value of type object variable of type string. what's benefit of allowing in case?

the code seems me highly bug; certainly compiler should telling rather allowing it.

c# .net compiler-construction null

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -