You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For some strings it is usefull to use the nameof()-Operator but the resulting string.Format() is not really needed.
Exsample
Exceptions can be defined like this: throw new InvalidCastException($"The type cannot be casted to {nameof(IMyInterface)}");
Version Used: Visual Studio 2015 Update 3, .NET Framework 4.5.2
Expected Behavior:
The compiler should remove the string.Format()-Method and use the string itself. throw new InvalidCastException("The type cannot be casted to IMyInterface");
Actual Behavior:
The result of the compiler is: throw new InvalidCastException(string.Format("The type cannot be casted to {0}", "IMyInterface"));
IL_001f: nop
IL_0020: ldstr "The type cannot be casted to {0}"
IL_0025: ldstr "IMyInterface"
IL_002a: call string [mscorlib]System.String::Format(string, object)
IL_002f: newobj instance void [mscorlib]System.InvalidCastException::.ctor(string)
IL_0034: throw
The text was updated successfully, but these errors were encountered:
For some strings it is usefull to use the
nameof()
-Operator but the resultingstring.Format()
is not really needed.Exsample
Exceptions can be defined like this:
throw new InvalidCastException($"The type cannot be casted to {nameof(IMyInterface)}");
Version Used: Visual Studio 2015 Update 3, .NET Framework 4.5.2
Expected Behavior:
The compiler should remove the
string.Format()
-Method and use the string itself.throw new InvalidCastException("The type cannot be casted to IMyInterface");
Actual Behavior:
The result of the compiler is:
throw new InvalidCastException(string.Format("The type cannot be casted to {0}", "IMyInterface"));
The text was updated successfully, but these errors were encountered: