SecretSoftware wrote:

AndyC wrote: 
SecretSoftware wrote: 

Well, the run time still can make type checking. What I mean is that the compiler should just infer the type of s from what its value type is, without writing extra keywords. This can be done while maintaining the type checking.


if (someCondition)
{
   s = new string();
} else {
   s = new int32();
}

//what type is s here?

Variant types like this are prone to misuse, bad for optimization and code analysis and just plain ugly.


s would be dependant on the condition. Initially s would be an object type and then its assigned to a string if someCondition is true, or if false would be assigned to a number.

This is present in other programming languages too, so its not a new thing.




You are missing the point here.  If I had code outside of the condition there would be no way to know what methods are avaible to s, meaning I would constantly have to use if conditions to determine the type of a variable before calling any methods on it.  Not that there aren't any benefits to this strategy but please leave C# alone and use javascript or another intepreted language.