Sponsored Ad

Thursday, October 22, 2009

C# Programs

This article will help you get started with C # by introducing some very simple programs. These are the objectives of this lesson:

  • Understand the basic structure of a C #.
  • Obtain a basic familiarization of what a "namespace" is.
  • Get a basic understanding of what a class is.
  • Learn what a Main method.
  • Learn how to get the command line input.
  • More about console input / output (I / O).

Simple C# Program

There are basic elements that all programs in C # executables have and that is what we focus on this first lesson, starting with a simple program in C #. After reviewing the code in Listing 1-1, I will explain the basic concepts are followed for all programs in C # that will write throughout this tutorial.

// Namespace Declaration
using System;

// Program start class
class WelcomeCSS
{
    // Main begins program execution.
    static void Main()
    {
        // Write to console
        Console.WriteLine("Welcome to the C# Station Tutorial!");
    }
}

This program has 4 primary elements, a namespace declaration, a class, a Main scheme, as well as a program statement. It can be compiled with the following command line:

csc.exe Welcome.cs

Hello World! program in C#

using System;
namespace HelloWorld
{
    class Hello
    {
        static void Main()
        {
            System.Console.WriteLine("Hello World!");

            // Keep the console window open in debug mode.
            System.Console.WriteLine("Press any key to exit.");
            System.Console.ReadKey();
        }
    }
}

Press F5 to run the project. A Command Prompt window appears that contains the line Hello World!

0 comments:

Post a Comment

Sponsored Ad

Website Update

Followers