What are the ways to write C # Hello World?
This article mainly introduces "what is the writing method of C # Hello World". In the daily operation, I believe that many people have doubts about the writing method of C # Hello World. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what is the writing method of C # Hello World?" Next, please follow the editor to study!
Introduction to writing C # Hello World:
1. Beginners
Public class HelloWorld {public static void Main () {System.Console.WriteLine ("HELLO WORLD");}}
two。 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 function
Using System; public class HelloWorld {public HelloWorld () {Console.WriteLine ("HELLO WORLD");} public static void Main () {HelloWorld hw = new HelloWorld ();}}
C # Hello World advanced writing:
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 ("HelloWorld");}}
7. Inherit
Abstract class HelloWorldBase {public abstract void writeHelloWorld ();} class HelloWorld: HelloWorldBase {public override void writeHelloWorld () {Console.WriteLine ("HelloWorld");}} class HelloWorldImp {static void Main () {HelloWorldBase hwb = HelloWorld; HelloWorldBase.writeHelloWorld ();}}
8. Static constructor
Using System; public class HelloWorld {private static string strHelloWorld; static HelloWorld () {strHelloWorld = "HelloWorld";} void writeHelloWorld () {Console.WriteLine (strHelloWorld);} public static void Main () {HelloWorld hw = new HelloWorld (); hw.writeHelloWorld ();}}
9. Exception handling
Using System; public class HelloWorld {public static void Main (string [] args) {try {Console.WriteLine (args [0]);} catch (IndexOutOfRangeException e) {Console.WriteLine (e.ToString ());}
10. Namespace
Using System; namespace HelloLibrary {public class HelloMessage {get {return "Hello, Worldworkers!";}-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 "HelloWorld";}} public static void Main () {HelloWorld hw = new HelloWorld (); Console.WriteLine (cs.strHelloWorld);}}
twelve。 Agent
Using System; class HelloWorld {static void writeHelloWorld () {Console.WriteLine ("HelloWorld");} static void Main () {SimpleDelegate d = new SimpleDelegate (writeHelloWorld); d ();}}
13. Working with attributes
# define DEBUGGING using System; using System.Diagnostics; public class HelloWorld: Attribute {[Conditional ("DEBUGGING")] public void writeHelloWorld () {Console.WriteLine ("HelloWorld");} 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 ("HelloWorld");} public static void Main () {HelloWorld hw = new HelloWorld (); hw.writeHelloWorld ();}}
C # Hello World is specially written:
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]); / / Instantiating 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. Unsafe code Hello World
Using System; public class HelloWorld {unsafe public void writeHelloWorld (char [] chrArray) {fixed (char * parr = chrArray) {char * pch = parr; for (int iTuno; I < chrArray.Length; iTuno +) Console.Write (* (pch+i));} public static void Main () {HelloWorld hw = new HelloWorld () Char [] chrHelloWorld = new char [] {'hw.writeHelloWorld (chrHelloWorld);}}
17. Use InteropServices
Using System; using System.Runtime.InteropServices; class Class1 {[DllImport ("kernel32")] private static extern int Beep (int dwFreq, int dwDuration); static void Main (string [] args) {Console.WriteLine ("Hello World"); Beep (1000, 2000);} at this point, the study of "how to write C # Hello World" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!