1.
beginner
Public class helloworld
{
Public static void main ()
{
System.Console.writeline ("Hello World");
}
}
2. Improved Hello World
Using system;
Public class helloworld
{
Public static void main ()
{
Console.writeline ("Hello World");
}
}
3. Command line form
Using system;
Public class helloworld
{
Public static void main (string [] args)
{
Console.writeline (args [0]);
}
}
4. Constructor
Using system;
Public class helloworld
{
Public HelloWorld ()
{
Console.writeline ("Hello World");
}
Public static void main ()
{
HelloWorld HW = New HelloWorld ();
}
}
5. Object-oriented
Using system;
Public class helloworld
{
Public void helloworld ()
{
Console.writeline ("Hello World");
}
Public static void main ()
{
HelloWorld HW = New HelloWorld ();
Hw.helloworld ();
}
}
6. From other classes
Using system;
Public class helloworld
{
Public static void main ()
{
HelloWorldhelperclass HWH = New HelloWorldHelperClass ();
HWh.writeHelloWorld ();
}
}
Public Class HelloWorldHelperClass
{
Public void writeHelloWorld ()
{
Console.writeline ("Hello World");
}
}
7. Inherited
Abstract Class HelloWorldBase
{
Public Abstract void writeHelloworld ();
}
Class HelloWorld: HelloWorldbase
{
Public override void writeHelloworld ()
{
Console.writeline ("Hello World");
}
}
Class HelloWorldimp
{
Static void main ()
{
HelloWorldBase HWB = HelloWorld;
HelloWorldBase.writeHelloWorld ();
}
}
8. Static constructor function
Using system;
Public class helloworld
{
Private static string strhelloworld;
Static HelloWorld ()
{
Strhelloworld = "Hello World";
}
Void writehelloworld ()
{
Console.writeline (strhelloworld);
}
Public static void main ()
{
HelloWorld HW = New HelloWorld ();
Hw.writehelloworld ();
}
9. Abnormal handling
Using system;
Public class helloworld
{
Public static void main (string [] args)
{
Try
{
Console.writeline (args [0]);
}
Catch (IndexOfficRangeexception E)
{
Console.writeline (E.TOString ());
}
}
}
10. Namespace
Using system;
Namespace Hellolibrary
{
Public Class Hellometage
{
Public String Message
{
get
{
Return "Hello, World !!!";
}
}
}
}
--------
Using system;
Using hellolibrary;
Namespace HelloApplication
{
Class HelloApp
{
Public static void main (string [] args)
{
HellOMessage M = New HellOMessage ();
}
}
}
11. Attribute
Using system;
Public class helloworld
{
Public String strhelloworld
{
get
{
Return "Hello World";
}
}
Public static void main ()
{
HelloWorld HW = New HelloWorld ();
Console.writeLine (cs.strhelloworld);
}
}
12. Agent
Using system;
Class HelloWorld
{
Static void writehelloworld ()
{
Console.writeline ("HelloWorld");
}
Static void main ()
{
SimpledeLegate D = New SimpleDelegate (WriteHelloWorld);
d ();
}
}
13. Using properties
#define debugging
Using system;
Using system.diagnostics;
Public Class HelloWorld: Attribute
{
[Conditional ("Debugging")]
Public void writeHelloWorld ()
{
Console.writeline ("Hello World");
}
Public static void main ()
{
HelloWorld HW = New HelloWorld ();
Hw.writehelloworld ();
}
}
14. Interface
Using system;
Interface IhelloWorld
{
Void writehelloworld ();
}
Public class helloworld: ihelloworld
{
Public void writeHelloWorld ()
{
Console.writeline ("Hello World");
}
Public static void main ()
{
HelloWorld HW = New HelloWorld ();
Hw.writehelloworld ();
}
}
15. Dynamic Hello World
Using system;
Using system.reflection;
Namespace helloworldns {
Public class helloworld
{
Public string writehelloworld ()
{
Return "HelloWorld";
}
Public static void main (string [] args)
{
TYPE HW = type.gettype (args [0]);
// instantiarating a class dynamically
Object [] nctorparams = new object [] {};
Object nobj = activator.createInstance (HW, nctorparams); //, nctorparams);
// invoking a method
Object [] nmthdparams = new object [] {};
String strhelloworld = (string) hw.invokemember ("WriteHelloWorld", BindingFlags.default | BindingFlags.InvokeMethod, Null, Nobj, NMTHDPARAMS);
Console.writeline (strhelloworld);
}
}
}
16. Not safe code Hello World
Using system;
Public class helloworld
{
UNSAFE PUBLIC VOID WRITEHELLOWORLD (CHAR [] Chrarray)
{
Fixed (Char * Parr = Chrarray)
{
CHAR * PCH = PARR;
For (int i = 0; i Console.write (* (PCH I)); } } Public static void main () { HelloWorld HW = New HelloWorld (); Char [] chrhelloworld = new char [] {'h', 'e', 'L', 'L', 'o', '', 'w', 'o', 'R', 'L', ' D '}; HW.writeHelloWorld (chrhelloworld); } } 17. Using InteropServices Using system; Using system.Runtime.InteropServices; Class class1 { [DLLIMPORT ("kernel32")]] Private static extern Int Beep; Static void main (string [] args) { Console.writeline ("Hello World"); BEEP (1000, 2000); } }