X hits on this document

1053 views

0 shares

0 downloads

0 comments

17 / 396

C# LANGUAGE SPECIFICATION

match a type declared in the source file.

1.3 Types and variables

There are two kinds of types in C#: value types and reference types. Variables of value types directly contain their data whereas variables of reference types store references to their data, the latter being known as objects. With reference types, it is possible for two variables to reference the same object and thus possible for operations on one variable to affect the object referenced by the other variable. With value types, the variables each have their own copy of the data, and it is not possible for operations on one to affect the other (except in the case of ref and out parameter variables).

C#’s value types are further divided into simple types, enum types, and struct types, and C#’s reference types are further divided into class types, interface types, array types, and delegate types.

The following table provides an overview of C#’s type system.

Category

Description

Value types

Simple types

Signed integral: sbyte, short, int, long

Unsigned integral: byte, ushort, uint, ulong

Unicode characters: char

IEEE floating point: float, double

High-precision decimal: decimal

Boolean: bool

Enum types

User-defined types of the form enum E {...}

Struct types

User-defined types of the form struct S {...}

Reference types

Class types

Ultimate base class of all other types: object

Unicode strings: string

User-defined types of the form class C {...}

Interface types

User-defined types of the form interface I {...}

Array types

Single- and multi-dimensional, for example, int[] and int[,]

Delegate types

User-defined types of the form delegate T D(...)

The eight integral types provide support for 8-bit, 16-bit, 32-bit, and 64-bit values in signed or unsigned form.

The two floating point types, float and double, are represented using the 32-bit single-precision and 64-bit double-precision IEEE 754 formats.

The decimal type is a 128-bit data type suitable for financial and monetary calculations.

C#’s bool type is used to represent boolean values—values that are either true or false.

Character and string processing in C# uses Unicode encoding. The char type represents a 16-bit Unicode code unit, and the string type represents a sequence of 16-bit Unicode code units.

The following table summarizes C#’s numeric types.

Category

Bits

Type

Range/Precision

4Copyright Microsoft Corporation 1999-2003. All Rights Reserved.

Document info
Document views1053
Page views1053
Page last viewedSat Dec 10 15:06:48 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments