FREE BOOK

Writing Windows C# Programs

Posted by Addison Wesley Free Book | C# Language July 21, 2009
The C# language has its roots in C++, Visual Basic, and Java. Both C# and VB.Net use the same libraries and compile to the same underlying code. Both are managed languages with garbage collection of unused variable space, and both can be used interchangeably. Both also use classes with method names that are very similar to those in Java, so if you are familiar with Java, you will have no trouble with C#.

Classes and Namespaces in C#
 
All C# programs are composed entirely of classes. Visual windows forms are a type of class. You will see that all the program features we'll be writing are composed of classes. Since everything is a class, the number of names of class objects can be overwhelming. They have therefore been grouped into various functional libraries that you must specifically mention in order to use the functions
 in these libraries. 
 
Under the covers these libraries are each individual DLLs. However, you need only refer to them by their base names, using the using statement, and the functions in that library are available to you.
 
 using System;
 
using System.Drawing;
 
using System.Collections;
 
Logically, each of these libraries represents a different namespace. Each namespace is a separate group of class and method names, which the compiler will recognize after you declare that namespace. You can use namespaces that contain identically named classes or methods, but you will only be notified of a conflict if you try to use a class or method that is duplicated in more than one namespace.
 
 
 The most common namespace is the System namespace, and it is imported  by default without your needing to declare it. It contains many of the most fundamental  classes and methods that C# uses for access to basic classes such as  Application, Array, Console, Exceptions, Objects, and standard objects such as  byte, bool, and string. In the simplest C# program we can simply write out a  message to the console without ever bringing up a window or form.
 
 
    class Hello
 
    {
         static void Main(string[] args)
         {
             Console.WriteLine("Hello C# World");
         }
 
    }
 
 This program just writes the text "Hello C# World" to a command (DOS)  window. The entry point of any program must be a Main method, and it must be declared as static.

Total Pages : 6 12345

comments