.net - C# ? : operator -


could explain me following compiler issue

error: type of conditional expression cannot determined because there no implicit conversion between 'string' , 'int'

// works string text = string.format(     "the id {0}", _obj.id.tostring());  // works, without implicit conversion <<< string text = string.format(     "the id {0}", _obj.id);  // works string text = string.format(     "the id {0}", (_obj == null) ? "unknown" : _obj.id.tostring());  // no way <<< string text = string.format(     "the id {0}", (_obj == null) ? "unknown" : _obj.id); 

in last example, there no implicit conversion, well.

eric lippert's cast operators not obey distributive law


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -