首页 > 其他 > 详细

类的封装

时间:2015-12-02 22:18:13      阅读:321      评论:0      收藏:0      [点我收藏+]

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;
}

}
}

类的封装

原文:http://www.cnblogs.com/hanghang0829/p/5014382.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!