Traditional "Hello World" Programme Using Different Approaches. PART-II.






4.40/5 (5 votes)
Oct 1, 2001

71740

2
Writing hello world program using different approaches in C#.
Hello World :)
In Part - I, I tried to explain the very basic "HELLO WORLD" program. In this article, I would use different methods to display "HELLO WORLD" so as to clear some of the OOPS fundamentals. So, without wasting much time, let's go on with it.
EXAMPLE: 1
/* In this Programme you must have noticed
that there is no base class declaration
here but to call WriteLine Method, Base class
i.e System is appended before Console.*/
public class nemesh
{
public static void Main()
{
System.Console.WriteLine("HELLO WORLD");
}
}
EXAMPLE: 2
using system;
public class nemeshc /* class declared as 'nemeshc' */
{
public void nemeshm() /* 'method declared as 'nemeshm' */
{
Console.WriteLine("HELLO WORLD");
}
public static void Main() /* Main Entry Point */
{
/* Object of class 'nemeshc' is constructed */
nemeshc nem = new nemeshc();
/* method 'nemeshm' of class 'nemeshc' is called*/
nem.nemeshm();
}
}
EXAMPLE: 3
using system;
public class nemeshc /* class declared as 'nemeshc' */
{
/* 'nemeshc' constructor is created and it fires when
the object of the class 'nemeshc' is constructed */
public nemeshc()
{
Console.WriteLine("HELLO WORLD");
}
public static void Main() /* Main Entry Point */
{
/* Object of class 'nemeshc' is constructed */
nemeshc nem = new nemeshc();
}
}
EXAMPLE: 4
using system;
public class nemeshc /* class declared as 'nemeshc' */
{
public static void Main() /* Main Entry Point */
{
/* Object of class 'nemesh1c' is constructed */
nemesh1c nem = new nemesh1c();
/* Method "neme1" of class 'nemesh1c' is called*/
nem.neme1();
}
}
public class nemesh1c /* class declared as 'nemesh1c' */
{
public void neme1() /* Method declared as 'neme1' */
{
Console.WriteLine("Hello World");
}
}
So folks! How was it? Did you get the things or all went above your head? If you are not able to understand any thing, then please mail me or just create a new thread and leave a message. I would try to explain it more deeply.
In my next article, I would explain to you "The beauty of .NET platform using C# and VB.NET".