1、结构跟C中类似,优点:集中处理常见任务,简化过程;
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace StructTest
7 {
8 struct huanghuang
9 {
10 public string firstName,lastName;
11 public string wholeName()
12 {
13 return firstName+" "+lastName;
14 }
15
16 }
17 class Program
18 {
19 static void Main(string[] args)
20 {
21 huanghuang hh;
22 hh.firstName="huang";
23 hh.lastName="huang";
24 Console.WriteLine("wholename = {0}",hh.wholeName());
25
26 }
27 }
28 }
2、重载,优点:不必显示指定要使用哪个函数,只需提供某某参数,就可以根据使用的参数执行相应的函数。
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace ReLoad
7 {
8 class Program
9 {
10 static double Play(double doublenum)
11 {
12 if (doublenum > 5.1)
13 return doublenum;
14 else
15 return 0;
16 }
17 static int Play(int intnum)
18 {
19 if (intnum > 5)
20 return intnum;
21 else
22 return 1;
23 }
24 static void Main(string[] args)
25 {
26 double t1 = 7.0;
27 int t2 = 7;
28 double m = Play(t1);
29 int n = Play(t2);
30 Console.WriteLine("m = {0},n = {1}",m,n);
31 }
32 }
33 }