Summary
This chapter presented the basic elements of writing a simple C# program. This included defining a class, which is the C# language element that defines an object. It also implemented a Main() method, which is the entry point of a program.
Three types of commenting syntax were discussed: single-line, multiline, and XML documentation comments. Single-line comments allow comments to reside on a single line. Multiline comments provide the capability to write comments that span multiple lines. XML documentation comments are special comments that use XML tags.
Identifiers (user-defined names given to variables and various program elements that the user defines) and keywords (reserved words used for the names of C# language elements) were defined. Ways to use whitespace and naming conventions to help make code easier to read and consistent with expected standards also were discussed.
The programs in this chapter are easy to compile with the command-line compiler. There were examples of command-line options to use to specify the executable file and output files for documentation comments. The /out option helps specify the output file. The /doc option produces XML documentation.
The various C# types and literal values they can accept were explained. These include the bool, integral, floating point, and decimal types. The bool type holds a Boolean true or false value. Integral types include a Unicode 3.0 character type and signed and unsigned forms of byte, short, integer, and long. Floating-point types are the float and long types. C# also introduces a new type, decimal, used primarily for financial calculations.
Structs, reference types, enums, and arrays were introduced. Structures are value types that are allocated on the stack and made for efficient manipulation of data. Reference types include classes, delegates, interfaces, and arrays. They are allocated and managed on the heap. Enums are lists of values with easy to read names and underlying types conforming to Integral type formats. Arrays are storage types that hold lists of data. Basic conversions were explained, as was the difference between implicit and explicit conversions.
This chapter finished up with demonstrations on how to interact with programs via the console and via the command line during startup. C# offers a plethora of built-in types to help make programs more expressive. The sections of this chapter presented the basics of the C# language. This essential bit of knowledge will help as you move to C# expressions.