作为一名合格的程序员来说,他的第一句代码,想必应该都是打印输出一句“Hello World”,这句最优美的程序语句,我想非常有必要单独来一篇来表达我对他的赞美!哇咔咔!!!
代码参考:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HelloWorld { class Program { static void Main(string[] args) { Console.WriteLine("Hello World"); } } }
截图运行输出:
代码解释:
//引入命名空间 using System; //定义命名空间 命名空间、类、方法都是以{开始,以}结束,分号;表示一条语句结束 namespace HelloWorld { //定义类 class Program { //特殊方法(Main方法比较特殊,编译器默认将此方法作为应用程序的起始点) static void Main(string[] args) { #region 方法体 #region 声明变量 string name = "王豆豆";//名称 short level = 99;//等级 int hp = 999;//血量 float exp = 888.666f;//经验值 Console.WriteLine("主角的名称是\"{0}\",等级是{1},血量是{2},经验值是{3}", name, level, hp, exp);//字符串格式化打印 #endregion #region @字符的使用,屏蔽转义字符,拼接多行字符串,格式化地址类型字符串 string str1 = @"愿程序不再有BUG, 你想多了!"; Console.WriteLine(str1); string str2 = @"程序员的世界,\n "" 你永远不懂!"; Console.WriteLine(str2); string path1 = "c:\\xxx\\xxx\\xxx\\Doc"; Console.WriteLine(path1); string path2 = @"c:\xxx\xxx\xxx\Doc"; Console.WriteLine(path2); #endregion Console.Write("Hello World1");//不换行打印 Console.WriteLine("Hello World2");//换行打印 Console.ReadKey();//调试过程中暂停显示输出界面 #endregion } //普通方法 static void TestMethod() { } } }
腹黑一句:世界是美好的,但是当你踏上程序猿这条不归路之后,你会发现,你的生活离正常人越来越远了