X hits on this document

782 views

0 shares

0 downloads

0 comments

88 / 396

Chapter ‎18   Unsafe code

class A { void F() { int i = 0; int j = new int(); } }

Because every value type implicitly has a public parameterless instance constructor, it is not possible for a struct type to contain an explicit declaration of a parameterless constructor. A struct type is however permitted to declare parameterized instance constructors (§‎11.3.8).

4.1.3 Struct types

A struct type is a value type that can declare constants, fields, methods, properties, indexers, operators, instance constructors, static constructors, and nested types. Struct types are described in §‎11.

4.1.4 Simple types

C# provides a set of predefined struct types called the simple types. The simple types are identified through reserved words, but these reserved words are simply aliases for predefined struct types in the System namespace, as described in the table below.

Reserved word

Aliased type

sbyte

System.SByte

byte

System.Byte

short

System.Int16

ushort

System.UInt16

int

System.Int32

uint

System.UInt32

long

System.Int64

ulong

System.UInt64

char

System.Char

float

System.Single

double

System.Double

bool

System.Boolean

decimal

System.Decimal

Because a simple type aliases a struct type, every simple type has members. For example, int has the members declared in System.Int32 and the members inherited from System.Object, and the following statements are permitted:

int i = int.MaxValue;// System.Int32.MaxValue constant string s = i.ToString();// System.Int32.ToString() instance method string t = 123.ToString();// System.Int32.ToString() instance method

The simple types differ from other struct types in that they permit certain additional operations:

Most simple types permit values to be created by writing literals (§‎2.4.4). For example, 123 is a literal of type int and 'a' is a literal of type char. C# makes no provision for literals of struct types in general, and non-

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

Document info
Document views782
Page views782
Page last viewedSat Dec 03 12:58:01 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments