C#函数的重载
来源:互联网 发布:算法设计与分析考试题 编辑:程序博客网 时间:2024/05/16 05:05
◆函数名必须相同方能构成函数重载;
◆函数返回值类型:可以相同,也可以不同(注意:函数的返回类型不足以区分两个重载函数);
◆函数参数类型:必须不同;
◆函数参数个数:可以相同,可以不同
◆函数参数顺序:可以相同,可以不同;
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication{ class Circle { private const float PI = 3.141526F; //1.没有任何已知条件 public static double Area() { Console.WriteLine("空空如也!"); return 0; } //2.已知圆心坐标 public static double Area(int x1, int y1) { Console.WriteLine("这是一个圆点,坐标为({0},{1})",x1,y1); return 0; } //3.已知半径 public static double Area(double r) { double theArea; theArea = PI * r * r; return theArea; } //4.已知圆心坐标和半径 public static double Area(int x1, int y1, double r) { Console.WriteLine("这是一个圆点在({0},{1})半径为{2}的圆", x1, y1, r); return Area(r); } //5.已知圆心和圆周边上的一点 public static double Area(int x1, int y1, int x2, int y2) { int x = x2 - x1; int y = y2 - y2; double r = (double)Math.Sqrt(x*x+y*y); Console.WriteLine("这是一个圆心在({0},{1}),圆周边一点在({2},{3})的圆,圆的半径为{4}",x1,y1,x2,y2,r); return Area(r); } static void Main(string[] args) { int x1=2,x2=4; //x坐标 int y1=3,y2=5; //y坐标 double radius=3; //半径 double CircleArea = 0; CircleArea = Area(); Console.WriteLine("-->1.面积为{0}",CircleArea); Console.WriteLine(); CircleArea = Area(x1,y1); Console.WriteLine("-->2.面积为{0}", CircleArea); Console.WriteLine(); CircleArea = Area(radius); Console.WriteLine("-->3.面积为{0}", CircleArea); Console.WriteLine(); CircleArea = Area(x1, y1, radius); Console.WriteLine("-->4.面积为{0}", CircleArea); Console.WriteLine(); CircleArea = Area(x1, y1, x2, y2); Console.WriteLine("-->5.面积为{0}", CircleArea); Console.WriteLine(); Console.ReadKey(); } }}
- C#函数的重载
- C#函数的重载
- C#构造函数的重载
- C# 构造函数的重载
- C#中函数的重载
- C#构造函数及其函数的重载
- C#中的函数重载
- C#中的函数重载
- c#函数重载
- C#函数重载问题
- C#函数重载
- C#构造函数的重载的几种方式
- C# 类的定义及构造函数的重载
- C# 构造函数及其重载
- C#的String.Split方法之6个重载函数
- C++与C#函数重载、隐藏与重写的异同
- C#构造函数的声明、重载与继承调用
- 函数 函数的重载
- iOS: About split view
- 老师笔记--第一天
- Compile and Test C5.0
- ubuntu10.04(64位)安装android sdk
- 第一次认识到erlang程序也是如此有趣
- C#函数的重载
- 【模拟】Another Easy Problem
- 面向对象设计原则之合成复用原则
- iphone No architectures to compile for (ARCHS=i386, VALID_AR
- 面向对象设计原则之迪米特法则
- TMD/WL (Themida / Winlicense ) SDK VM的解决方案 (应用篇,非引擎分析)
- hdoj 1253 胜利大逃亡 宽度优先遍历
- Java中的异常对程序效率有无影响
- USACO Riding The Fences 与欧拉路径问题