Skip to Main Content
C# in a Nutshell, Second Edition
book

C# in a Nutshell, Second Edition

by Peter Drayton, Ben Albahari, Ted Neward
August 2003
Intermediate to advanced content levelIntermediate to advanced
928 pages
32h 1m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell, Second Edition

Name

IConvertible

Synopsis

The IConvertible interface allows conversion of an object to basic data types and allows the conversion methods in the Convert class to use that object. When implementing the IConvertible interface, create your own type-specific methods for each of the supplied conversion methods.

Note that IConvertible allows one-way conversion from a custom type to other data types, but does not allow a conversion from a basic data type to a custom type.

public interface IConvertible {
// Public Instance Methods
   public TypeCode GetTypeCode( );
   public bool ToBoolean(IFormatProvider provider);
   public byte ToByte(IFormatProvider provider);
   public char ToChar(IFormatProvider provider);
   public DateTime ToDateTime(IFormatProvider provider);
   public decimal ToDecimal(IFormatProvider provider);
   public double ToDouble(IFormatProvider provider);
   public short ToInt16(IFormatProvider provider);
   public int ToInt32(IFormatProvider provider);
   public long ToInt64(IFormatProvider provider);
   public sbyte ToSByte(IFormatProvider provider);
   public float ToSingle(IFormatProvider provider);
   public string ToString(IFormatProvider provider);
   public object ToType(Type conversionType,  IFormatProvider provider);
   public ushort ToUInt16(IFormatProvider provider);
   public uint ToUInt32(IFormatProvider provider);
   public ulong ToUInt64(IFormatProvider provider);
}

Implemented By

Multiple types

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

C# in a Nutshell

C# in a Nutshell

Ben Albahari, Ted Neward, Peter Drayton
C# 7.0 in a Nutshell

C# 7.0 in a Nutshell

Joseph Albahari, Ben Albahari
C# Cookbook, 2nd Edition

C# Cookbook, 2nd Edition

Jay Hilyard, Stephen Teilhet
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard

Publisher Resources

ISBN: 0596005261Catalog PageErrata