This chapter provided an overview of the type system in C# and looked at the simple types in particular.

The important points we have discussed are as follows:

In object-oriented programming, types are used as building blocks to form other types.

Two ways can be used to divide the predefined types in C#: Simple types vs. derived types and value types vs. reference types. The former is often more convenient, the latter is the most correct.

All values belonging to a specific type share a set of predefined characteristics.

Every value must be of a specific type. There are strict rules in C# for the operations a value of a specific type can take part in. For that reason C# is termed a strongly typed language.

A strongly typed language allows us to write powerful declarative statements in the source code.

A variable of a value type holds the actual data stored in it. A reference type holds a reference to another part of the memory where the data are stored. int is a value type, string is a reference type.

It is possible for more than one value of the same reference type to reference the same object.

Important predefined value types in C# are the simple types, and enum types. All value types are structs.

Important predefined reference types are strings, arrays, interfaces, and delegates. All reference types are classes.

You can define your own classes and structs.

The syntax of a computer language provides the rules to follow for writing a valid source program. Syntax is exact and is best expressed with an exact notation form. A Backus-Naur resembling notation form was introduced for use in the rest of the book.

C# has thirteen predefined simple types that allow you to find a suitable type for most simple values you need to represent. Of those thirteen types, nine are integers, two are floating-point, one is high precision, and one is Boolean.

A predefined implicit conversion path exists between the different simple numeric types. The compiler automatically performs implicit conversions. Explicit conversions, written explicitly in the source code, are needed to move against the direction of this path.

An integer type variable overflows when its value becomes larger than the maximum range specified by the type. Its value is then set to the minimum specified by the range. Underflow is the same process reversed.

Working with the simple types presents several subtle issues you should be aware of to prevent errors in the source code.

The value of a constant is specified in the source code and cannot be changed after compilation. An identifier in the source code represents the value.

C# allows you to format numeric values for printout, providing improved readability.

Values of type bool can represent just two values: true and false.


C# Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: