C# 接口
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyInterface
{
interface PolygonInterface
{
float Area();
int Circumference();
void Type();
}
public class TriangleClass : PolygonInterface
{
private int edge1;
private int edge2;
private int edge3;
public TriangleClass() { }
public void SetEdge(int edge1, int edge2, int edge3)
{
this.edge1 = edge1;
this.edge2 = edge2;
this.edge3 = edge3;
}
public float Area()
{
float s = (edge1 + edge2 + edge3) * 0.5f;
float area = (float)Math.Sqrt(s * (s - edge1) * (s - edge2) * (s - edge3));
return area;
}
public int Circumference()
{
return edge1 + edge2 + edge3;
}
public void Type()
{
Console.WriteLine("This is TriangleClass");
}
}
class Program
{
static void Main(string[] args)
{
TriangleClass triangleClass = new TriangleClass();
triangleClass.SetEdge( 6, 8, 10);
float area = triangleClass.Area();
float circum = triangleClass.Circumference();
triangleClass.Type();
Console.WriteLine(string.Format("area = {0}, circum = {1}", area, circum));
Console.WriteLine("\n");
Console.Read();
}
}
}