C#: Convert Double to Integer…and other conversions

Type conversions and casting in C# are so whack!  Microsoft created the System.Convert class to bring some sanity and predictability to converting from one type to another in C#.  Without further ado, to convert a Double to an Integer, you can use:   int myInt = System.Convert.ToInt32(myDouble);

The System.Convert class has the following methods:

  • ToBoolean
  • ToByte
  • ToChar
  • ToDateTime
  • ToDecimal
  • ToDouble
  • ToInt16
  • ToInt32
  • ToInt64
  • ToSingle
  • ToString
  • and some more….

Comments are closed.

Powered by WordPress. Designed by Woo Themes