结构与重载

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 }



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值