using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 接口约定参数
{
classProgram
{
staticvoid Main(string[]args)
{
DoMath m1 = new DoMath();
Console.WriteLine(m1.Add(10,100));
IMath im = newMath1();
im.x = 100; im.y = 100; im.MathType="Add";
im = m1.math(im);
Console.WriteLine(im.result);
IMath im1 = new Math2();
im1.x = 100; im1.y = 100;im1.MathType ="Add";
im1 = m1.math(im1);
Console.WriteLine(im1.result);
Console.ReadKey();
}
}
publicclass DoMath
{
publicint Add(int x,int y)
{
returnx + y;
}
publicIMath math(IMath m)
{
if(m.MathType.ToLower() == "add")
{
m.result = m.x + m.y;
}
returnm;
}
}
publicinterface IMath
{
int x {get;set; }
int y {get;set; }
stringMathType {get; set;}
intresult {get; set;}
}
publicclass Math1 :IMath
{
publicint x { get; set; }
publicint y { get; set; }
publicstring MathType { get;set; }
publicint result { get;set; }
}
publicclass Math2 :IMath
{
int _x;
publicint x
{
get{
return_x + 100;
}
set{
this._x= value;
}
}
publicint y { get; set; }
publicstring MathType { get;set; }
publicint result { get;set; }
}
}
接口约定参数
最新推荐文章于 2022-08-10 10:20:01 发布