Hello C#

Given my background, C# looks strangely familiar. Sort of a jump in a parallel dimension. It is close to Java, but it is actually not the same. It remembers C++, being definitely something else. And it even has something of old dear Pascal in its Delphi flavour.

Here is how to say hello, writing to the console:

class Hello
{
public static void Main()
{
System.Console.WriteLine("Hello C#");
System.Console.ReadLine();
}
}

Notice the (wierd, from my point of view) uppercase initial for function names.

Using the GUI interface is almost as simple as writing to the console:

using System.Windows.Forms; // 1.

class Hello
{
public static void Main()
{
System.Windows.Forms.MessageBox.Show("Hello C#");
}
}

The only (and minor) issue is that we have to tell the compiler where to get the System.Windows.Forms namespace. System.Console is so standard that we have not to bother about, but this other one has to be specified.

We have to insert in the project an "assembly reference" to the required additional packages. Luckly this is done in a very intuitive mode in the developing environment.

No comments:

Post a Comment