方法的重载
来源:互联网 发布:ubuntu deb 编辑:程序博客网 时间:2024/05/07 16:35
Ø 使用数据类型不同的参数重载方法(方法名相同,数据类型不同)
Ø 使用不同数目的参数重载方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 方法的重载
{
classProgram
{
staticvoid Main(string[] args)
{
//方法一
myclassp =newmyclass();
Console.WriteLine(p.add(12,12));
Console.WriteLine(p.add(12d,12d));
Console.WriteLine(p.add(12d,12d, 12d));
int[]x = new int[5]{ 1, 2, 3, 4, 5 };
Console.WriteLine(p.add(x));
//方法二
//Console.WriteLine(newmyclass{}.add(1,2));
//Console.WriteLine(newmyclass { }.add(1.1d, 2.2d));
//Console.WriteLine(newmyclass { }.add(1.1d, 2.2d,3.3d));
//int[] x= new int[5] { 1, 2, 3, 4, 5 };
//Console.WriteLine(newmyclass { }.add(x));
Console.ReadKey();
}
}
publicclassmyclass
{
publicobject add(int x,int y)//定义2个int;
{
returnx + y;
}
publicobject add(doublex,double y)//2个及多个参数
{
returnx + y;
}
publicobject add(double x,double y,double z)
{
returnx + y + z;
}
publicobject add(paramsint[] p)//多个参数时
{
int outx= 0;
foreach(var item in p)//简单迭代器返回值¦
{
outx += item ;
}
returnoutx ;
}
}
}
Ø
- 方法的重载
- 重载新的方法
- 关于方法的重载
- 方法的重载
- java方法的重载
- 方法重载的 依据??
- 方法的重载
- 方法的重载
- 方法重载的例子
- java 方法的重载
- 方法的重载
- 重载equals的方法
- 构造方法的重载
- 简单的方法重载
- JAVA 方法的重载
- java 方法的重载
- 方法的重载
- 方法重载的学习
- object-c 属性
- MPLAB v8常见设置
- 【多媒体封装格式详解】---MP4【1】
- 熊太郎's present
- 详细介绍双网卡内外网同时使用的方法
- 方法的重载
- 本次操作由于计算机的限制而被取消,请与管理员联系
- 读 Beginning Android Games 2nd Edition (十二) 把框架基础功能放入Game类中
- frame和iframe的区别
- 关于敏捷方法的一次沟通记录
- Eclipse 的列编辑模式
- 使用这些提示,帮助你的减肥计划
- 解决MySQL中【Cannot load from mysql.proc. The table is probably corrupted。】的问题
- 构造函数