类的封装
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;
}
}
}
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;
}
}
}
相关文章推荐
- ecshop后台支付方式的报错(2)
- linux增加vlan网卡配置
- 配置(更改)tomcat的端口
- CDH5.1使用CDH Manager安装
- 1027. 打印沙漏(20)
- html/css
- ecshop后台支付方式的报错(1)
- OpenCV入门:(三:图片Mask operations)
- ios面试题(2)
- Eclipse Project 无故消失的解决办法
- Linux下C++的编程——开偏介绍
- arm-linux内核启动学习笔记(一)
- LeetCode-Remove Duplicates from Sorted List II
- 关于ECSHOP模板架设的服务器php版本过高报错的解决
- Base64
- node js 调试
- 可删除的对象
- (二十七)整型字面值(常量)——多种进制
- 博弈论基础知识: 巴什博奕+威佐夫博奕+尼姆博弈(及Staircase
- JNI调用C++类的方式