ZZ writes 17 forms of Hello World with C #

xiaoxiao2021-03-06  59

Learn

1. A Beginners Hello WorldPublic Class HelloWrld {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 application jobization 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

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. 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 [] chrray) {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;

转载请注明原文地址:https://www.9cbs.com/read-112700.html

New Post(0)