码迷,mamicode.com
首页 > 其他好文 > 详细

类的封装

时间:2015-12-02 22:20:46      阅读:155      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!