zoukankan
html css js c++ java
委托事件之买烟
由于家住在五楼,晚上我的精品白沙烟抽完了.然而自己不想下楼去商店买,于是
委托
我的朋友去买.打算买10包.
using
System;
using
System.Collections.Generic;
using
System.Text;
namespace
BuyCigarette
{
class
Program
{
static
void
Main(
string
[] args)
{
Console.Write(
"
请输入买烟的数量:
"
);
//
声明BuyCigarettesEvent类的一个实例
BuyCigarettesEvent m
=
new
BuyCigarettesEvent();
m.BuyCigarette
+=
new
BuyCigarettesEvent.EventDelegate(Result);
//
BuyCigarette事件交给EventDelegate委托去做
//
转换用户输入,并调用Buy方法
m.Buy(
int
.Parse(Console.ReadLine()));
//
输出总价格
Console.WriteLine(
"
总价格为:
"
+
m.Price
+
"
元人民币
"
);
Console.ReadKey(
false
);
}
//
事件处理函数。
static
void
Result(
object
sender, EventArgs e)
{
Console.WriteLine(
"
朋友去买烟了
"
);
}
}
public
class
BuyCigarettesEvent
{
//
首先声明一个委托
public
delegate
void
EventDelegate(
object
sender, EventArgs e);
//
声明一个事件
public
event
EventDelegate BuyCigarette;
//
价格
public
int
Price;
public
void
Buy(
int
number)
{
Price
=
number
*
10
;
//
假如是买的是精品白沙烟10元一包
if
(BuyCigarette
!=
null
)
{
BuyCigarette(
this
,
new
EventArgs());
//
响应事件
}
}
}
}
结果显示:
查看全文
相关阅读:
.jardesc文件
job.setOutputKeyClass(IntWritable.class) job.setOutputValueClass(Text.class);
java 发送 http请求——HttpClient
封装java发送邮件
Mybatis使用log4j添加日志
一些jar命令
js 发送ajax请求
JDBC
初始化
Maven创建项目之后不显示src/main/java资源文件夹
原文地址:https://www.cnblogs.com/xiaobaigang/p/1031554.html
最新文章
spring+quarts常见问题
属性只有一个值的这类 html 属性是怎么回事,该如何设置值;比如:checked = “checked” vs checked = true
解决MySql 数据库 提示:1045 access denied for user 'root'@'localhost' using password YES
mysql 修改数据库密码
MyEclipse打开JSP文件报"Failed to create the part's controls"解决方法汇总
文件下载
文件大小限制
表单中普通字段中文乱码处理
关闭linux退格键和vi发出的嘟嘟声(报警声)
SQL Server 执行计划
热门文章
Ajax工作原理
FileStream 转换成Stream
常用前端组件
sql截取逗号分隔的字符串实例
如何禁止和关闭windows自动更新
HTTP 错误 404.17
由于 Web 服务器上的“ISAPI 和 CGI 限制”列表设置,无法提供您请求的页面。
.net 根据模板创建html文件
java 二进制 位运算符
Servlet init
Copyright © 2011-2022 走看看