Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Different programming languages use different terms to identify the fundamental managed types. Class library designers must avoid using language-specific terminology. Follow the rules described in this section to avoid type name confusion.
Use names that describe a type's meaning rather than names that describe the type. In the rare case that a parameter has no semantic meaning beyond its type, use a generic name. For example, a class that supports writing a variety of data types into a stream might have the following methods.
Sub Write(value As Double);
Sub Write(value As Single);
Sub Write(value As Long);
Sub Write(value As Integer);
Sub Write(value As Short);
[C#]
void Write(double value);
void Write(float value);
void Write(long value);
void Write(int value);
void Write(short value);
Do not create language-specific method names, as in the following example.
Sub Write(doubleValue As Double);
Sub Write(singleValue As Single);
Sub Write(longValue As Long);
Sub Write(integerValue As Integer);
Sub Write(shortValue As Short);
[C#]
void Write(double doubleValue);
void Write(float floatValue);
void Write(long longValue);
void Write(int intValue);
void Write(short shortValue);
In the extremely rare case that it is necessary to create a uniquely named method for each fundamental data type, use a universal type name. The following table lists fundamental data type names and their universal substitutions.
C# type name | Visual Basic type name | JScript type name | Visual C++ type name | Ilasm.exe representation | Universal type name |
---|---|---|---|---|---|
sbyte | SByte | sByte | char | int8 | SByte |
byte | Byte | byte | unsigned char | unsigned int8 | Byte |
short | Short | short | short | int16 | Int16 |
ushort | UInt16 | ushort | unsigned short | unsigned int16 | UInt16 |
int | Integer | int | int | int32 | Int32 |
uint | UInt32 | uint | unsigned int | unsigned int32 | UInt32 |
long | Long | long | __int64 | int64 | Int64 |
ulong | UInt64 | ulong | unsigned __int64 | unsigned int64 | UInt64 |
float | Single | float | float | float32 | Single |
double | Double | double | double | float64 | Double |
bool | Boolean | boolean | bool | bool | Boolean |
char | Char | char | wchar_t | char | Char |
string | String | string | String | string | String |
object | Object | object | Object | object | Object |
For example, a class that supports reading a variety of data types from a stream might have the following methods.
ReadDouble()As Double
ReadSingle()As Single
ReadInt64()As Long
ReadInt32()As Integer
ReadInt16()As Short
[C#]
double ReadDouble();
float ReadSingle();
long ReadInt64();
int ReadInt32();
short ReadInt16();
The preceding example is preferable to the following language-specific alternative.
ReadDouble()As Double
ReadSingle()As Single
ReadLong()As Long
ReadInteger()As Integer
ReadShort()As Short
[C#]
double ReadDouble();
float ReadFloat();
long ReadLong();
int ReadInt();
short ReadShort();
See Also
Design Guidelines for Class Library Developers | Common Type System