13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 11 Types11.1.3 Simple types<strong>C#</strong> provides a set of predefined struct types called the simple types. The simple types are identified throughreserved words, but these reserved words are simply aliases for predefined struct types in the Systemnamespace, as described in the table below.Reserved wordsbytebyteshortushortintuintlongulongcharfloatdoublebooldecimalAliased typeSystem.SByteSystem.ByteSystem.Int16System.UInt16System.Int32System.UInt32System.Int64System.UInt64System.CharSystem.SingleSystem.DoubleSystem.BooleanSystem.DecimalBecause a simple type aliases a struct type, every simple type has members. [Example: For example, inthas the members declared in System.Int32 and the members inherited from System.Object, and thefollowing statements are permitted:int i = int.MaxValue;// System.Int32.MaxValue constantstring s = i.ToString(); // System.Int32.ToString() instance methodstring t = 123.ToString(); // System.Int32.ToString() instance methodend example] The simple types differ from other struct types in that they permit certain additionaloperations:• Most simple types permit values to be created by writing literals (§9.4.4). [Example: For example, 123is a literal of type int and 'a' is a literal of type char. end example] <strong>C#</strong> makes no provision for literalsof struct types in general, and non-default values of other struct types are ultimately always createdthrough instance constructors of those struct types.• When the operands of an expression are all simple type constants, the compiler evaluates the expressionat compile-time. Such an expression is known as a constant-expression (§14.15). Expressions involvingoperators defined by other struct types are not considered to be constant expressions.• Through const declarations, it is possible to declare constants of the simple types (§17.3). It is notpossible to have constants of other struct types, but a similar effect is provided by static readonlyfields.• Conversions involving simple types can participate in evaluation of conversion operators defined byother struct types, but a user-defined conversion operator can never participate in evaluation of anotheruser-defined operator (§13.4.2).11.1.4 Integral types<strong>C#</strong> supports nine integral types: sbyte, byte, short, ushort, int, uint, long, ulong, and char. Theintegral types have the following sizes and ranges of values:• The sbyte type represents signed 8-bit integers with values between –128 and 127.91

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!