自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C# Main函數(shù)概念以及應(yīng)用祥解

開發(fā) 后端
C# Main函數(shù)的概念是什么呢?C# Main函數(shù)的形式是什么呢?那么本文就向你詳細介紹C# Main函數(shù)的這些情況,希望對你了解和學(xué)習(xí)C# Main函數(shù)有所幫助。

C# Main函數(shù)的概念是什么呢?C# Main()是C#應(yīng)用程序的入口點,執(zhí)行這個函數(shù)就是執(zhí)行應(yīng)用程序。也就是說,在執(zhí)行過程開始時,會執(zhí)行Main()函數(shù),在Main()函數(shù)執(zhí)行完畢時,執(zhí)行過程就結(jié)束了。

C# Main函數(shù)的四種情況:

  1. static void Main()  
  2. {  
  3.  }  
  4. static int Main()  
  5. {  
  6.  }  
  7. static void Main(string[] args)  
  8. {  
  9.  }  
  10.  static int Main(string[] args)  
  11.  {  
  12.   } 

1.主程序Main函數(shù)一共有以上四種版

2.一個程序中不能有兩個以上的Main函數(shù),有且只有一個

3.Main函數(shù)只能返回int類型,如果返回1,則從命令行調(diào)用不成功。否則成功

4.在命令行傳輸參數(shù)時,存放在string數(shù)組args中。使用Length屬性來測試輸入?yún)?shù)的個數(shù)。

5.使用foreach語句來檢索所有的參數(shù)
 
6.程序入口主要供其他程序來執(zhí)行本程序功能
 
C# Main函數(shù)實例:

  1.  //Main() 和命令行參數(shù)  
  2.  
  3. /*以檢舉數(shù)組中所有元素訪問信息  
  4.    for each (string str int args(  
  5.  Console.WriteLine(str);*/ 
  6. using System;  
  7. using System.Collections.Generic;  
  8. using System.Text;  
  9.  
  10. namespace HelloWorld  
  11. {  
  12. class Program  
  13. {  
  14. public static long getx(int x)     
  15. //階乘 (注:使用Static定義的方法不用實例化就能使用)  
  16. {  
  17. long y = 1;  
  18. for (int i = 2; i<=x; i++)  
  19. {  
  20. y =y * i;  
  21. }  
  22. return y;  
  23. }  
  24. public static long gety(int x)   //階加  
  25. {  
  26. long y = 0;  
  27. for (int i = 1; i <= x; i++)  
  28. {  
  29. y += i;  
  30. }  
  31. return y;  
  32. }  
  33. static int Main(string[] args)  
  34. {  
  35. if (args.Length != 1)     
  36. //測試args[]數(shù)組的長度 ------即是輸入的命令行的參數(shù)是多少  
  37. {  
  38. Console.WriteLine("程序使用說明:輸入一個整數(shù)來算出其的階乘.");  
  39. Console.WriteLine(" 輸入一個整數(shù)來算出其的階加.");  
  40. }  
  41. else if (Convert.ToInt32(args[0]) < 1 )  
  42. {  
  43. Console.WriteLine("輸入?yún)?shù)不能小于1");  
  44. }  
  45. else 
  46. {  
  47. int x; long y,z;  
  48. try 
  49. {  
  50. x = Convert.ToInt32(args[0]);  
  51. y = getx(x);  
  52. z = gety(x);  
  53. Console.WriteLine(x + "的階乘為: " + y);  
  54. Console.WriteLine(x + "的階加為: " + z);  
  55. return 1;  //返回1表示調(diào)用程序成功執(zhí)行  
  56. }  
  57. catch(Exception ex)  
  58. {  
  59. Console.WriteLine(ex.ToString());  
  60. }  
  61. }  
  62. }  
  63. }  
  64. }  

C# Main函數(shù)實例執(zhí)行結(jié)果

C# Main函數(shù)實例執(zhí)行結(jié)果 

C# Main函數(shù)的概念和實例的基本內(nèi)容就向你介紹到這里,希望對你了解和學(xué)習(xí)C# Main函數(shù)有所幫助。

【編輯推薦】

  1. C#DES算法實例解析
  2. C#DES加密解密的實現(xiàn)實例淺析
  3. .NET C# DES入門淺析
  4. C#從C和C++繼承的特點淺談
  5. 淺談C#向Java學(xué)習(xí)的體現(xiàn)
責(zé)任編輯:仲衡 來源: 百度空間
相關(guān)推薦

2009-09-04 18:09:12

C# Main函數(shù)

2009-08-28 13:12:56

C#反射實例C#反射

2009-09-09 10:47:29

C# CheckBox

2009-08-18 09:51:18

C#枚舉類型

2009-08-20 18:47:19

C#異步通信

2009-08-24 17:39:21

C# 泛型集合

2009-09-03 09:16:35

C#遞歸函數(shù)

2009-08-13 18:02:50

C#基礎(chǔ)概念

2009-09-04 18:16:19

C# Main參數(shù)C# Main

2009-08-12 10:37:13

C#運算符重載

2009-08-28 16:48:50

C#多態(tài)性

2009-08-31 16:51:11

C# Main()方法

2021-07-27 15:56:28

MaxCompute 資源優(yōu)化

2009-08-13 14:24:44

C#結(jié)構(gòu)體構(gòu)造函數(shù)

2009-09-01 15:47:20

C#取整函數(shù)

2009-09-02 10:58:02

C#動態(tài)數(shù)組

2010-01-27 13:31:10

C++ main()函

2010-01-19 14:28:41

C++ main()函

2019-06-10 19:00:23

Cmain函數(shù)編程語言

2009-09-17 17:44:51

C#動態(tài)數(shù)組
點贊
收藏

51CTO技術(shù)棧公眾號