O'Reilly logo

Learning C# by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. C# Language Fundamentals

Chapter 2 demonstrates a very simple C# program that prints the text string “Hello world!” to the console screen and provides a line-by-line analysis of that program. However, even that very simple program was complex enough that some of the details had to be skipped over. The current chapter begins an in-depth exploration of the syntax and structure of the C# language.

Types

C# is a strongly typed language. That means that every object you create or use in a C# program must have a specific type (e.g., you must declare the object to be an integer or a string or a Dog or a Button). The type tells the compiler how big the object is and what it can do.

Types come in two flavors: those that are built into the language (intrinsic types) and those you create (classes, structs, and interfaces, discussed in Chapter 8, Chapter 13, and Chapter 14, respectively). C# offers a number of intrinsic types, shown in Table 5-1.

Table 5-1. The intrinsic types

Type

Size (in bytes)

.NET type

Description

byte

1

Byte

Unsigned (values 0-255).

char

2

Char

Unicode characters.

bool

1

Boolean

True or false.

sbyte

1

SByte

Signed (values-128 to 127).

short

2

Int16

Signed (short) (values-32,768 to 32,767).

ushort

2

UInt16

Unsigned (short) (values 0 to 65,535).

int

4

Int32

Signed integer values between -2,147,483,648 and 2,147,483,647.

uint

4

UInt32

Unsigned integer values between 0 and 4,294,967,295.

float

4

Single ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required