using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Data.SqlClient;
using System.Text;
using System.Data;
namespace ConsoleApp17
{
class Test
{
static void Main(string[] args)
{
int a, b, c, h, m;
a = 3; b = 4; c = 5; h = 4; m = 1;
Console.WriteLine("a={0},b={1},c={2},h={3},m={4}", a, b, c, h, m);
Console.Read();
Area e = new Area(a, b);
Area f = new Area(a, b, c);
Area g = new Area(c, b, a);
Area i = new Area(a, b, c, m);
Console.WriteLine("三角形面积为{0}", e);
Console.WriteLine("三角形面积为{0}", f);
Console.WriteLine("三角形面积为{0}", g);
Console.WriteLine("三角形面积为{0}", i);
} }
class Area
{
public float Areac(float a, float h)
{
float area = (float)(a * h / 2);
return area;
}
public float Areac(float a, float b, float c)
{
double p;
p = (a + b + c) / 2.0;
float area = (float)Math.Sqrt((p * (p - a) * (p - b) * (p - c)));
return area;
}
public float Areac(double c, float b, float a)
{
double CosB = (a * a + c * c - b * b) / (2 * c * a);
double SinB = System.Math.Sqrt(1 - CosB * CosB);
float area = (float)(0.5 * a * c * SinB);
return area;
}
public float Areac(float a, float b, float c, float m)
{
float area= (a + b + c) * m / 2;
return area;
}
}
为什么函数命名Area时说类型不能重名,命名areac时上面的赋值又不能成功
一、函数名;
二、函数返回值类型;
三、函数参数类型;
四、函数参数个数;
五、函数参数顺序;
◆函数名必须相同方能构成函数重载;
◆函数返回值类型:可以相同,也可以不同(注意:函数的返回类型不足以区分两个重载函数);
◆函数参数类型:必须不同;
◆函数参数个数:可以相同,可以不同,参数个数相同时,类型不能相同。
◆函数参数顺序:可以相同,可以不同;
◆注意:参数表的比较过程与参数名无关.