Skip to Content
.NET Common Language Runtime Unleashed
book

.NET Common Language Runtime Unleashed

by Kevin Burton
April 2002
Intermediate to advanced content levelIntermediate to advanced
1024 pages
23h 26m
English
Sams
Content preview from .NET Common Language Runtime Unleashed

System.Convert

This class converts one base type to another base type. All of the basic types are represented in each version, but that conversion might not actually occur. Three different cases exist:

  • No conversion takes place. An example of this is converting a type to itself.

  • If the conversion does not make sense, the Convert class method throws an exception (InvalidCastException, FormatException, OverflowException, and so on).

  • The Convert method succeeds in making the conversion.

Listing B.4 shows an example of a conversion from a string read in the Console to a DateTime structure (convert.cs).

Listing B.4. Conversion Example
 public static void Main(String[] args) { Console.Write("Input a date: "); string input = Console.ReadLine(); try { ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Customizing the Microsoft® .NET Framework Common Language Runtime

Customizing the Microsoft® .NET Framework Common Language Runtime

Steven Pratschner

Publisher Resources

ISBN: 0672321246Purchase book