Lecture overview -- Keyboard shortcut: 'u'  Previous page: C# in relation to C [Section] -- Keyboard shortcut: 'p'  Next page: Enumerations types -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 7 : 43
Object-oriented Programming in C#
Introduction to C#
Simple types

This page is about integers, real numbers, characters, and booleans.

Most simple types in C# are similar to the simple types in C

  • Major differences:

    • All simple C# types have fixed bit sizes

    • C# has a boolean type called bool

    • C# chars are 16 bit long

    • In C# there is a high-precision 128 bit numeric fixed-point type called decimal

    • Pointers are not supported in the normal parts of a C# program

      • In the unsafe part C# allows for pointers like in C

    • All simple types are in reality structs in C#, and therefore they have members

Differences compared to C.

/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/simple-types/ex1.csDemonstrations of the simple type bool in C#.

Shows boolean constants and how to deal with the default boolean value (false).

/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/simple-types/ex2.csDemonstrations of the simple type char in C#. This program is explained

Illustrates character constants, hexadecimal escape notation, and character methods.

/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/simple-types/ex3.csDemonstrations of numeric types in C#.

Illustrates all numeric types in C#. Exercises minimum and maximum values of the numeric types.

/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/simple-types/outputOutput from the numeric demo program.

Output from the program above. Reveals minimum and maximum values of all the numeric types.

Go to exerciseExploring the type Char
Go to exerciseHexadecimal numbers