1. A Beginners Hello Worldpublic class HelloWorld {public static void Main () {System.Console.WriteLine ( "HELLO WORLD");}}. 2 Slightly improved versionusing System; public class HelloWorld {public static void Main () {Console. WriteLine ( "HELLO WORLD");}} 3. Command Line Argumentsusing System; public class HelloWorld {public static void Main (string [] args) {Console.WriteLine (args [0]);}} 4. From Constructorusing System; Public class helloworld {public helloworld () {console.writeline ("Hello World");}
Public static void main () {helloworld hw = new helloworld ();}} 5. more oil {public class helloworld () {Console.writeline ("Hello World");}
public static void Main () {HelloWorld hw = new HelloWorld (); hw.HelloWorld ();}} 6 From another classusing 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. Inheritanceabstract 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 Constructorusing 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 Exception Handlingusing System;. public class HelloWorld {public static void Main (string [] args) {try {Console.WriteLine ( args [0]);} catch (IndexOutOfRangeException e) {Console.WriteLine (e.ToString ());.}}} 10 Creating a DLL and using it in an applicationusing System; namespace HelloLibrary {public class HelloMessage {public string Message {Get {return "Hello, World !!!";}}}} // ------
Using system; using hellolibrary;
Namespace helloApplication {class helloApp {
Public static void main (string [] args) {hellomessage m = new hellMessage ();
}}} 11. Using PropertyUsing System; Public Class HelloWorld {public string strhelloworld {get {return "hello world"}}
public static void Main () {HelloWorld hw = new HelloWorld (); Console.WriteLine (cs.strHelloWorld);}} 12 Using Delegatesusing System;. class HelloWorld {static void writeHelloWorld () {Console.WriteLine ( "HelloWorld"); } Static void main () {SimpleDelegate D = New SimpleDelegate (WriteHelloWorld); d ();}} 13. Using attributes # define debugging job.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. using interfacesusing 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 WorldUsing 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);
// invoking a method
object [] nmthdParams = new object [] {}; string strHelloWorld = (string) hw.InvokeMember ( "writeHelloWorld", BindingFlags.Default | BindingFlags.InvokeMethod, null, nobj, nmthdParams);
Console.WriteLine (strHelloWorld);}}} 16 Unsafe Hello Worldusing System;. Public class HelloWorld {unsafe public void writeHelloWorld (char [] chrArray) {fixed (char * parr = chrArray) {char * pch = parr; for (int i = 0; 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.UNTEROPSERVICESUSTEM.RUNTIME.ITEROPSERVICES; Class class1 {[DLLIMPORT ("kernel32")] private statino; int dwfreq, int dwduration;