C#_事件学习
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Lab7_4
{
class Stock
{
public delegate void PriceRise(double money); //定义委托
public delegate void PriceDown(double money); public event PriceRise PriceRiseEvent; //定义事件
public event PriceDown PriceDownEvent; private string stockName;
private double stockPrice; public string StockName {
set;
get;
} public double StockPrice {
set;
get;
} public Stock(string name, double price) {
stockName = name; stockPrice = price;
} public void priceRise(double up) {
Console.WriteLine("股票上升: {0}", up);
PriceRiseEvent(up); //触发事件 } public void priceDown(double down) {
Console.WriteLine("股票下降: {0}", down);
PriceDownEvent(down);
} }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Lab7_4
{
class Buyer
{
private Stock stock; //卖家要抛售的股票 public Buyer(Stock s) {
stock = s;
} public void StockPriceRise(double up) { if (up > 0.05) {
Console.WriteLine("股票上涨已经超过5%, 买家谨慎买入");
} else {
Console.WriteLine("股票正在小幅上涨, 买家可以买入");
}
} public void StockPriceDown(double down) {
if (down > 0.05) {
Console.WriteLine("股票下跌已经超过0.05,买家可以逢低买入");
} else {
Console.WriteLine("股票正在小幅下跌,买家暂时请观望");
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Lab7_4
{
class Seller
{
private Stock stock; //卖家要抛售的股票 public Seller(Stock s) {
stock = s;
} public void StockPriceRise(double up) { if (up > 0.05) {
Console.WriteLine("股票上涨已经超过5%, 卖家请赶快抛售");
} else {
Console.WriteLine("股票正在小幅上涨, 卖家可以继续观望");
}
} public void StockPriceDown(double down) {
if (down > 0.05) {
Console.WriteLine("股票下跌已经超过0.05,卖家请逢低补仓");
} else {
Console.WriteLine("股票正在小幅下跌,卖家请谨慎操作");
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Lab7_4
{
class Program
{
static void Main(string[] args) { Console.WriteLine("输入股票名: ");
Stock stock = new Stock(Console.ReadLine(), ); Buyer buyer = new Buyer(stock);
Seller seller = new Seller(stock); //注册事件
stock.PriceRiseEvent += buyer.StockPriceRise;
stock.PriceDownEvent += buyer.StockPriceDown; stock.PriceRiseEvent += seller.StockPriceRise;
stock.PriceDownEvent += seller.StockPriceDown; //触发事件
Console.WriteLine("输入涨率: ");
stock.priceRise(double.Parse(Console.ReadLine()));
Console.WriteLine("输入降率: ");
stock.priceDown(double.Parse(Console.ReadLine())); }
}
}
C#_事件学习的更多相关文章
- Mysql事件学习
出自:http://blog.chinaunix.net/uid-20639775-id-3323098.html Mysql事件学习 在系统管理或者数据库管理中,经常要周期性的执行某一个命令或者SQ ...
- C#_事件
C#_事件 概述 今天用来演示事件的例子是模拟实现一个文件下载类,在这个类中我将定义一个DownLoad事件,这个事件用来在文件下载的过程中,向订阅这个事件的用户发出消息,而这个消息将用DownLoa ...
- centos5.5字体为方块问题的解决_深入学习编程_百度空间
centos5.5字体为方块问题的解决_深入学习编程_百度空间 centos5.5字体为方块问题的解决 一.yum -y install fonts-chinese二.yum -y install f ...
- C#委托与事件学习笔记
委托事件学习笔记 本文是学习委托和事件的笔记,水平有限,如有错漏之处,还望大神不吝赐教. 什么是委托?从字面意思来解释,就是把一个动作交给别人去执行.在实际开发中最常用的就是使一个方法可以当做一个参数 ...
- C# event 事件学习
C# event 事件学习 运行环境:Window7 64bit,.NetFramework4.61,C# 6.0: 编者:乌龙哈里 2017-02-26 章节: 简单事件编写 模拟 WPF 控件传递 ...
- 安卓开发_深入学习ViewPager控件
一.概述 ViewPager是android扩展包v4包(android.support.v4.view.ViewPager)中的类,这个类可以让用户左右切换当前的view. ViewPager特点: ...
- 《JS高程》事件学习笔记
事件:文档或浏览器窗口中发生的一些特定的交互瞬间,也即用户或浏览器自身执行的某种动作. -------------------------------------------------------- ...
- JS 点击事件学习总结
废话篇: 在我们编写无论什么网页内容的时候我们总是或多或少的要接触到点击事件这一范畴的,写过几个简短的demo和网页之后,感觉自己对电机事件一类的东西了解也更为的清楚了,之前写过很多零零散散的东西现在 ...
- android touchEvent事件学习
学习网址:http://www.apkbus.com/forum.php?mod=viewthread&tid=44296 1:Android Touch事件传递机制解析 android系统中 ...
随机推荐
- 【动态规划】POJ-2229
一.题目 Description Farmer John commanded his cows to search for different sets of numbers that sum to ...
- vmware_vcenter_api
VMware Vcenter_API 介绍 本文主要通过调用Vcenter_API,获取其中的数据中心,集群,主机,网络,存储,虚拟机信息. 开发语言 python 使用官方sdk pyvmomi 文 ...
- Windows Apache(ApacheHaus)安装配置教程
1,Apache下载 选择一个版本,点击Download 点击File For Microsoft Windows 由于Apache HTTP Server官方不提供二进制(可执行)的发行版,所以我们 ...
- vue 实战报错解决方案
最近做项目,遇到一个问题 列表滚动,上拉加载功能 采用了better-scroll 插件,将better-scroll 封装成组件,采用父组件传递值给子组件的方式,子组件 采用$emit 方式 通知父 ...
- Internet History, Technology and Security (Week 9)
Week 9 Security: Web Security We are now on the second to last week of the class and finishing up ou ...
- Rsyslog日志服务搭建
rsyslog是比syslog功能更强大的日志记录系统,可以将日志输出到文件,数据库和其它程序.Centos 6.x默认的rsyslog版本是5.x. 网上关于rsyslog的安装配置文档倒是不少,但 ...
- 如何快速地编写和运行一个属于自己的 MapReduce 例子程序
大数据的时代, 到处张嘴闭嘴都是Hadoop, MapReduce, 不跟上时代怎么行? 可是对一个hadoop的新手, 写一个属于自己的MapReduce程序还是小有点难度的, 需要建立一个mave ...
- 为phpstorm安装右侧代码预览工具
打开设置界面,进入到plugins页面,然后再搜索codeglance,然后点击安装即可.
- [微软官方]FSUTIL
Applies To: Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7, Windows Server 2003 ...
- 使用Word 进行UTF8 以及字符串编码的转换操作
1. 使用Word文档能够实现 字符串和utf8编码的转换. 快捷键是 ALT+X 在知乎的一个里面看到一个说法: ㍾ ㍽ ㍼ ㍻ - 这四个在Unicode表里是倒序排列的,而且只预留了这四个年号, ...