[Mono-dev] [PATCH] Avoid useless check in Convert.ToChar(ushort)

Kornél Pál kornelpal at gmail.com
Sat Nov 15 13:39:05 EST 2008


Andreas Färber wrote:
> 
> Am 15.11.2008 um 12:32 schrieb Kornél Pál:
> 
>> Index: mcs/class/corlib/System/Convert.cs
>> ===================================================================
>> --- mcs/class/corlib/System/Convert.cs    (revision 118898)
>> +++ mcs/class/corlib/System/Convert.cs    (working copy)
>> @@ -681,10 +681,6 @@
>>         [CLSCompliant (false)]
>>         public static char ToChar (ushort value)
>>         {
>> -            if (value > Char.MaxValue)
>> -                throw new OverflowException (Locale.GetText (
>> -                    "Value is greater than Char.MaxValue"));
>> -   
>>             return (char)value;
>>         }
> 
> Does .NET throw an InvalidCastException? No exception is documented.

This conversion is supported by C# and Convert as well. The check is 
useless because the range of char and ushort is exactly the same 
(0-65535) so this exception would never be thrown.

Kornél


More information about the Mono-devel-list mailing list