The Primitive Types Available in C

Team-Fly    

 
.NET and COM Interoperability Handbook, The
By Alan Gordon
Table of Contents
Chapter Four.  A Quick Introduction to C#

The Primitive Types Available in C#

The list of primitive types available in C# is very similar to C and C++. One of the major reasons for the cross-language interoperability of the .NET Framework is that all languages share a common type system: the CTS. The primitive types in C# are just aliases for CTS types. Table 4-4 shows the primitive types available in C#.

Table 4-4. A Mapping of C# types to CTS types

C# Types

CLS Compliant

Equivalent CTS Type

Description

bool

Yes

System.Boolean

True or false

byte

Yes

System.SByte

Unsigned 8-bit number

sbyte

No

System.Byte

Signed 8-bit number

char

Yes

System.Char

16-bit Unicode character

int

Yes

System.Int32

Signed 32-bit number

uint

No

System.UInt32

Unsigned 32-bit number

long

Yes

System.Int64

Signed 64-bit number

ulong

No

System.UInt64

Unsigned 64-bit number

short

Yes

System.Int16

Signed 32-bit number

ushort

No

System.UInt16

Unsigned 32-bit number

float

Yes

System.Single

32-bit floating point number

double

Yes

System.Double

64-bit floating point number

system.DateTime

Yes

System.DateTime

Date time

decimal

Yes

System.Decimal

Signed 96-bit number

string

Yes

System.String

Unicode character string.

object

Yes

System.Object

Base class for all types

Most of the familiar primitive types from C and C++ like int, long, short, char, float, and double are present in C#. C# also supports unsigned types like uint, ushort, and unlong, but keep in mind that these unsigned types are not CLS compliant. Therefore, if you do expose types from your libraries that use these unsigned types in their interface, those libraries will not be usable from many managed code languages including VB.NET. Avoid unsigned types in your interfaces if you want to write components that may be consumed by languages other than C#.

Note

The CLS specifies the features that all managed code languages must support as a minimum.


With C#, as in most managed-code languages, you can use either the language-specific alias or the CTS type name freely and interchangeably. In other words, declaring a variable to be of type "int" is exactly the same as declaring it to be of type "System.Int32". In addition, a function that accepts a parameter of type float will also accept a parameter that is typed as System.Single.


Team-Fly    
Top
 


. Net and COM Interoperability Handbook
The .NET and COM Interoperability Handbook (Integrated .Net)
ISBN: 013046130X
EAN: 2147483647
Year: 2002
Pages: 119
Authors: Alan Gordon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net