C# Language Fundamentals Consider this chapter a potpourri (Web hosting directory)

C# Language Fundamentals Consider this chapter a potpourri of core topics regarding the C# language and the .NET platform. Unlike forthcoming chapters, there is no overriding example or theme; rather, the following pages illustrate a number of bite-size topics you must become comfortable with, including value-based and reference-based data types, decision and iteration constructs, boxing and unboxing mechanisms, the role of System.Object, and basic class-construction techniques. Along the way, you ll also learn how to manipulate CLR strings, arrays, enumerations, and structures using the syntax of C#. To illustrate these language fundamentals, you ll take a programmatic look at the .NET base class libraries and build a number of sample applications, making use of various types in the System namespace. This chapter also examines a new C# 2005 language feature, nullable data types. Finally, you ll learn how to organize your types into custom namespaces using the C# namespace keyword. The Anatomy of a Simple C# Program C# demands that all program logic is contained within a type definition (recall from Chapter 1 that type is a term referring to a member of the set {class, interface, structure, enumeration, delegate}). Unlike in C(++), in C# it is not possible to create global functions or global points of data. In its simplest form, a C# program can be written as follows: // By convention, C# files end with a *.cs file extension. using System; class HelloClass { public static int Main(string[] args) { Console.WriteLine(”Hello World!”); Console.ReadLine(); return 0; } } Here, a definition is created for a class type (HelloClass) that supports a single method named Main(). Every executable C# application must contain a class defining a Main() method, which is used to signify the entry point of the application. As you can see, this signature of Main() is adorned with the public and static keywords. Later in this chapter, you will be supplied with a formal definition of public and static. Until then, understand that public members are accessible from other types, while static members are scoped at the class level (rather than the object level) and can thus be invoked without the need to first create a new class instance. 65 C H A P T E R 3
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Leave a Reply