Wednesday, February 7, 2007

first application in csharp

In csharp , everything is a class
This follows the java analogy where everything is a class too.
This disallows the concept of using functions without a class
IN simple terms , u want a function put it in a class :)

The starting point in any csharp application is the function Main( Note that it is
Main and not main as found in Java and C++).

This being a function is neverthless contained within a class.
Also in C# , u create projects.
The essence of creating it as a project is to facilate enterprise level developement
from scratch
and to overcome the problem posed by the make file utility

now lets get started



namespace first{ //compulsory

class classone {// remember everything is a class

public static void Main(String args[]){//captial M in main

Console.WriteLine("welcome to programming in c#");
Console.ReadLine(); //analogus to getch() in c , pause for enter before the o/p window is closed
}
}

Now

1) namespace : this is to avoid variable naming collison
analogous to package and can be imported.

2)args-----> here csharp follows the syntax of java
unlike c,c++ which have two feilds argc and argv
there is only one argv
and note that argv[0] contains the first argument and not the
program name as in c and c++
this is similar to the java enviornment.

3) Note the definition of a new data type String
Once again Java has been copied here

4) Console.Readline and Console.WriteLine :
These are used to read from and write to the console.
Strange that they are contained in the namespace System.

One thing about Console.ReadLine ,
this differs from your scanf and cin , in the sense that it does not take
any arguments.
it rather returns a string
so we ought to parse it
for ex:
double a ;
a = double.parse(Console.ReadLine());

This is analogous to Java and vb

No comments: