Friday, April 4, 2008

C#. No1 - Getting started...

/resource from http://www.csharp-station.com/

Some of my friends want to learn C# and requested me to post about C#.
Below A Simple Welcome Program: Welcome.cs

// 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!");
}
}

Warning: C# is case-sensitive. The word "Main" is not the same as its lower case spelling, "main". They are different identifiers. If you are coming from a language that is not case sensitive, this will trip you up several times until you become accustomed to it.

Getting Interactive Input: InteractiveWelcome.cs
// Namespace Declaration
using System;

// Program start class
class InteractiveWelcome
{
// Main begins program execution.
public static void Main()
{
// Write to console/get input
Console.Write("What is your name?: ");
Console.Write("Hello, {0}! ", Console.ReadLine());
Console.WriteLine("Welcome to the C# Station Tutorial!");
}
}
Also you can change line Console.Write("Hello, {0}! ", Console.ReadLine()); to
string name = Console.ReadLine();
Console.Write("Hello, {0}! ", name);
Here Console.ReadLine() reads value from keyboard.
Is is same as code below witten in C++

char str [80];
scanf("What is your name?: %s",str);
printf("Hello, %s", str);
printf("Welcome to the C# Station Tutorial!");

0 comments: