标签:
1 //传值:四种方式: 2 //1.没有输入值和返回值 3 //2.没有输入有返回 4 //3.没有返回有输入 5 //4.有返回有输入 6 7 //传址 8 9 10 11 12 /// <summary> 13 /// 累加求和,没有输入值,没有返回值; 14 /// </summary> 15 public void leijia() 16 { 17 Console.Write("请输入一个正整数"); 18 int a = int.Parse(Console.ReadLine()); 19 int sum = 0; 20 for (int i = 1; i <= a; i++) 21 { 22 sum += i; 23 } 24 Console.WriteLine(sum); 25 } 26 /// <summary> 27 /// 累加求和,没有返回值,有输入值 28 /// </summary> 29 /// <param name="a"></param> 30 public void leijia(int a) 31 { 32 33 int sum = 0; 34 for (int i = 1; i <= a; i++) 35 { 36 sum += i; 37 } 38 Console.WriteLine(sum); 39 } 40 /// <summary> 41 /// 累加求和,没有输入值,只有返回值(int) 42 /// </summary> 43 /// <returns></returns> 44 public int leijia1() 45 { 46 Console.Write("请输入一个正整数"); 47 int a = int.Parse(Console.ReadLine()); 48 int sum = 0; 49 for (int i = 1; i <= a; i++) 50 { 51 sum += i; 52 } 53 return sum; 54 55 } 56 /// <summary> 57 /// 累加求和,有输入值(int),有返回值(int) 58 /// </summary> 59 /// <param name="a"></param> 60 /// <returns></returns> 61 public int leijia1(int a) 62 { 63 int sum = 0; 64 for (int i = 1; i <= a; i++) 65 { 66 sum += i; 67 } 68 return sum; 69 70 }
标签:
原文地址:http://www.cnblogs.com/Itwonderful/p/5272037.html