A simple c# Hello World program
Hello all, a lot of you who are new to .NET or the CSC.EXE (or mono(linux)) compiler that comes with it for windows will be wondering what the syntax and learnability of c# is like. Well I think we’ve established it’s practically javascript in an MS wrapper - it - much like javascript - has some really powerful C++ like syntax and formating to it. Below I include a quick Hello World Program I wrote by scratch. Notice the adoption of the class structure, c# is full of it - again, much like JS.
I’ve compiled this application in VS c# 2008, and it should also work fine in VS c# 2005 as well as the CSC.EXE. If you are using VS c# 2008 to write, compile and run your applications use shift+f6 (builds application) followed by a F5 (debug/run) keypress once you have typed in the code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace JustAQuickHelloWorldbyAzio
{
class Azio // name of class
{
public string mystring; // named string mystring of type string, publically declared (accessible outside class)
}
class Program
{
static void Main(string[] args)
{
Azio anotherazio = new Azio(); // create an object for my Azio class, lets call the object “anotherazio”
anotherazio.mystring = “Hi thar!”; // initialize the mystring data member of anotherazio object of type Azio class
Console.WriteLine(”Hello World says ” + anotherazio.mystring); // Tell the c# Console (commandline) to output
// the text “Hello World says ” and the value of anotherazio.mystring which is respectfully “Hi thar!”
Console.ReadKey(); // this line instructs the program to wait for any userkey press to exit the program.
} // end of Main() function (scope)
} // end of class Program (scope)
} // end of namespace (scope)
I’ve actually just quickly reviewed the c# programming language over the last few days (& as best I can), I thought it would be nice to see a simple-esque hello world application that included classes and basic foundations of OOP, it seems to be so easy in c# in comparison to C++ but mm, then again maybe my previous experience helps
Peace,
A