|This article—Hello, CSharp—is from C# Primer: A Practical Approach, by Stanley B. Lippman. Copyright © 2002 Pearson Education, Inc. All rights reserved. Reproduced by permission. This article has been edited especially for C# Online.NET.|
This chapter attempts to capture your interest while grounding you in the fundamentals of C#. Stan Lippman introduces the language elements as they become necessary to implement a small first program. For those more traditionally minded, the chapter ends with a summary listing of the predefined language elements. He also covers simple types, as well as the namespace and exception-handling mechanisms.
My daughter has cycled through a number of musical instruments. With each one she is anxious to begin playing the classics—no, not Schubert or Schoenberg, but the Backstreet Boys and Britney Spears. Her various teachers, keen to keep her interest while grounding her in the fundamentals, have tended to indulge her. In a sense this chapter attempts the same precarious balance in presenting C#. In this context the classics are represented by Web Forms and Type Inheritance. The fundamentals are the seemingly mundane predefined language elements and mechanisms, such as scoping rules, arithmetic types, and namespaces. My approach is to introduce the language elements as they become necessary to implement a small first program. For those more traditionally minded, the chapter ends with a summary listing of the predefined language elements.
C# supports both integral and floating-point numeric types, as well as a Boolean type, a Unicode character type, and a high-precision decimal type. These are referred to as the simple types. Associated with these types is a set of operators, including addition (
+), subtraction (
-), equality (
==), and inequality (
!=). C# provides a predefined set of statements as well, such as the conditional
switch statements and the looping
foreach statements. All of these, as well as the namespace and exception-handling mechanisms, are covered in this chapter.