Chapter 3. C# Language Fundamentals
Chapter 2 demonstrates a very simple C# program. Nonetheless, there is sufficient complexity in creating even that little program that some of the pertinent details had to be skipped over. The current chapter illuminates these details by delving more deeply into the syntax and structure of the C# language itself.
This chapter discusses the type system in C#, drawing a distinction
between built-in types (int
,
bool
, etc.) versus user-defined types (types you
create as classes and interfaces). The chapter also covers
programming fundamentals such as how to create and use variables and
constants. It then goes on to introduce enumerations, strings,
identifiers, expressions, and statements.
The second part of the chapter explains and demonstrates the use of
branching, using the if
,
switch
, while
,
do...while
, for
, and
foreach
statements. Also discussed are operators,
including the assignment, logical, relational, and mathematical
operators. This is followed by an introduction to namespaces and a
short tutorial on the C# precompiler.
Although C# is principally concerned with the creation and manipulation of objects, it is best to start with the fundamental building blocks: the elements from which objects are created. These include the built-in types that are an intrinsic part of the C# language as well as the syntactic elements of C#.
Types
C# is a strongly typed language. In a strongly typed language you must declare the type of each object you create ...
Get Programming C# now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.