日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#Main函數(shù)概念以及應(yīng)用祥解

C# Main函數(shù)的概念是什么呢?C# Main()是C#應(yīng)用程序的入口點(diǎn),執(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ù)實(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定義的方法不用實(shí)例化就能使用)  
  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ù)實(shí)例執(zhí)行結(jié)果

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


分享名稱:C#Main函數(shù)概念以及應(yīng)用祥解
網(wǎng)站網(wǎng)址:http://m.5511xx.com/article/cohdige.html