In this part of the C# tutorial, we will cover basic programming concepts of the C# language. We introduce the very basic programs. We will work with variables, constants and basic data types. We will read and write to the console; we will mention variable interpolation.
Simple Programm
-------------------------------------------
using System;
public class Example { static void Main() { Console.WriteLine("This is C#"); } }How to run:
- using c# command line compiler csc.exe
c:\>csc Example.cs [compile, its generate .exe]
c:\> Example
Understanding:
using System;The
using
keyword imports a specific namespace to
our program.public class Example { ... }Each C# program is structured. It consists of classes and its members. A class is a basic building block of a C# program. The
public
keyword gives unrestricted access to this
class. The Main() is a method. A method is a piece of code created to do a specific job. Instead of putting all code into one place, we divide it into pieces, called methods. This brings modularity to our application. Each method has a body, in which we place statements. The body of a method is enclosed by curly brackets. The specific job for the Main() method is to start the application. It is the entry point to each console C# program. The method is declared to be
static
. This static method can be called without the need
to create an instance of the CSharApp class. First we need start the application
and after that, we are able to create instances of classes.
Console.WriteLine("This is C#");
void - main() does not return value.
static - A method that is modified by static can be called before an object of its class has been created.
using System; public class Example { static void Main() { string name; Console.Write("Enter your name: "); name = Console.ReadLine(); Console.WriteLine("Hello {0}", name); } }
0 comments:
Post a Comment