您的位置:首页 > 其它

类的封装

2015-12-02 21:45 429 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 简易运算
{
class Pack //封装
{
private int x;
private int y;
private string oper;
private int anster = 0;

public int OP
{
set
{
x = value;
}
get
{
return x;
}
}
public int Pt
{
set
{
y = value;
}
get
{
return y;
}
}
public string Oper
{
set
{
oper = value;

}
get
{
return oper;
}
}
public int Aster
{
get
{
return anster;
}
}
public int yusuan()
{
switch (oper)
{
case "+":
anster = x + y;
break;
case "-":
if (x > y)
anster = x - y;
//else
// throw new Exception("被减数不能小于减数,既不能出现负数");
break;
case "*":
anster = x * y;
break;
case "/":
//if (y == 0)
//{
// throw new Exception("被除数不能等于零!");

//}
//else
anster = x / y;
break;
}
return anster;

}
public int fanhui()
{
return anster;
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: