Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Convert.ToInt32(DateTime) exist?

Tags:

c#

.net

Simply curious, MSDN says that

Calling this method always throws InvalidCastException.

So why does this overload exist in the framework? Is it following some sort of pattern? I would assume for backwards compatibility it would be better to remove the overload and receive compile errors rather than run-time exceptions. I don't remember if this method was actually supported in previous frameworks though.

like image 232
Stan R. Avatar asked Dec 09 '10 18:12

Stan R.


People also ask

What does convert ToInt32 mean?

ToInt32(String, IFormatProvider) Converts the specified string representation of a number to an equivalent 32-bit signed integer, using the specified culture-specific formatting information. ToInt32(String, Int32) Converts the string representation of a number in a specified base to an equivalent 32-bit signed integer.

Does convert ToInt32 handle null?

Convert. ToInt32 allows null value, it doesn't throw any errors Int.


1 Answers

As you can see in the documentation in the link you provided:

Remarks

This method is reserved for future use.

They simply haven't found an implementation they are happy with or is necessary, but they are planning for it to be so.

like image 173
Joel Etherton Avatar answered Sep 17 '22 15:09

Joel Etherton