Ch02.C#语言基础
ch02 第二章 系统分析

3
B.3 ACC.3 RS0 EXEN2 PT1 P3.3 ET1 P2.3 TB8 P1.3 IE1 P0.3
2
B.2 ACC.2 OV TR2 PX1 P3.2 EX1 P2.2 RB8 P1.2 IT1 P0.2
1
B.1 ACC.1 ? C_T2 PT0 P3.1 ET0 P2.1 TI P1.1 IE0 P0.1
(a) EA 1 (8051)
(b) EA 1 (8052)
(c) EA 0 (8051 / 8052)
11
2.7 数据存储器(RAM)
数据存储器(RAM)
数据存储器主要用途是暂存资料 内部数据存储器,8051有128Bytes,8052有256Bytes 0x7F 外部数据存储器,最大64KB
系统重置
SW
+5V
VCC (40)
10µF
RST (9)
10k
VSS (20)
表2-1 SFR 暫存器
PC ACC B PSW SP P0 P1 P2 P3 DPTR
系統重置之特殊功能暫存器(SFR)初始值 暫存器位址
未定 0xE0 0xF0 0xD0 未定 0x80 0x90 0xA0 0xB0 DPL=0x82 DPH=0x83 0x0000 0x00 0x00 0x00 0x07 0xFF 0xFF 0xFF 0xFF 0x00 0x00
暫存器位址
重置設定值
XXX00000B XX000000B 0XX00000B 0X000000B 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 未定 0XXXXXXXB 0XXX0000B
ch02国民收入核算

GDP不能反映分配是否公平
• 人均GDP的增加代表一个国家人民平均收入水平的增加,从而当一个 国家的人均GDP增加时,这个国家的平均福利状况将得到改善。
• 但是,由于收入分配的不平等,一小部分人得到了更多的收入,大 多数人的收入水平并没有增加,或增加得较少,因此他们的福利状 况并没有得到改善,或没有得到明显的改善。
明国内生产总值及其核算
ch02国民收入核算
学习目的与要求
• 掌握国内生产总值的概念。 • 通过对收入流量循环模型的学习,掌握核算经济体系总产出的
两种基本方法。 • 理解国民收入核算中五个总量的关系。 • 理解总需求与总供给的恒等关系。 • 掌握潜在国内生产总值的概念
ch02国民收入核算
§1、国民收入核算的历史
ch02国民收入核算
GDP缺口
• 潜在的GDP与实际GDP之间的差距叫做GDP缺口 • GDP缺口可以衡量放弃的本来可以生产出来的物品和劳务。因此,缺
口表现了经济衰退以及资源浪费的情况,表现出失业的情况。
GDP
潜在GDP
GDP缺口 0
实际GDP
t
ch02国民收入核算
五、GDP核算的意义与局限
1、意义 ❖通过实际GDP能够计算经济增长率,它反映一个国家的经济增长和
一、支出法
从全社会看,总产出=购买最终产品的总支出
• 如生产了一件上衣卖50元, • 这50元对生产者来说,就是生产和经营上衣的五个阶段的厂商(棉
农、纱厂、织布厂、服装厂及上衣销售商创造的价值(新增价值) ,就是他们的总产出 • 这50元对消费者来说,就是消费者的支出
ch02国民收入核算
总支出包含存货投资
通过实际GDP能够计算经济增长率,它反映一个国家 的经济增长和变动情况。
ch02会计要素与会计恒等式

PPT文档演模板
ch02会计要素与会计恒等式
•主营业务 成本等
•费 用
•其他业 务支出
•投资损失
PPT文档演模板
•所得税
•营业外支出
ch02会计要素与会计恒等式
费用的特征
• A 由过去的 交易或事项中 产生,耗费已 发生(应负担 )或已成为事 实(已支付款 项)
•费 用
• B 会引起资 产减少或负债 增加(如预提 费用),或二 者兼而有之
对静态会计等式的理解
第一,静态会计等式体现了同一资金的两个 不同侧面:资金存在形态与资金来源渠道;
•资产
•资 金
•资 金
•资 •负债 金 •所有
者权益
•资金存在形态
•资金来源渠道
PPT文档演模板
ch02会计要素与会计恒等式
第二,以货币计量时,会计等式双方数额 相等;
PPT文档演模板
•资产
•资 金
•收入
• C 可增加 利润,因而 也可增加所 有者权益
• D 仅指属 于本企业经 济利益的流 入,不包括 代收款项等
PPT文档演模板
ch02会计要素与会计恒等式
(二)企业会计要素的内容
费用——是指企业为销售商品、提供劳 务等日常活动所发生的经济利益的流出。 包括:
• 计入成本的费用——计入生产成本的 直接材料、直接人工和制造费用以及 计入劳务成本的各种成本费用
收入——是指企业在销售商品、提供劳 务及让渡资产使用权等日常活动中所形 成的经济利益的总流入。包括:
• 主营业务收入——销售商品、产成品、 工业性劳务等收入
• 其他业务收入——除主营业务以外的 其他销售收入或其他劳务的收入(使 用费收入、租金收入等)
ch02国际经济学课后答案与习题(萨尔瓦多)

ch02国际经济学课后答案与习题(萨尔⽡多)*CHAPTER 2Chapter) (CoreCOMPARATIVE ADVANTAGEOUTLINE2.1 Introduction2.2 Mercantilists’ Views on TradeCase Study 2-1 Mercantilism Is Alive and Well in the Twenty-First Century2.3 Trade Based on Absolute Advantage: Adam Smith2.4 Trade Based on Comparative Advantage: David Ricardo2.5 Gains from Trade with Comparative Advantage2.6 Comparative Advantage with MoneyCase Study 2-2 The Petition of the Candlemakers2.7 Comparative Advantage and Opportunity CostsCase Study 2-3 Labor Productivities and Comparative Advantage2.8 Production Possibility Frontier with Constant Costs2.9 Opportunity Costs and Relative Commodity Prices2.10 Basis and Gains from Trade Under Constant CostsAppendix: Comparative Advantage with More than Two Commodities and NationsA2.1 Comparative Advantage with More than Two CommoditiesA2.2 Comparative Advantage with More than Two NationsKey TermstheoryofvalueLabortradeBasisfortheorytrade OpportunitycostGainsfromtrade Production possibility frontierofPatterncostopportunityConstantMercantilismcommodityRelativeprices advantageAbsolutespecializationCompleteLaissez-faireLaw of comparative advantage Small-country case-7-Lecture Guide1. This is a long and crucial core chapter and may require four classes to cover adequately. In thefirst lecture, I would present Sections 1-4 and assign review questions 1-3.2. In the second lecture of Chapter 2, I would concentrate on Sections 5-6 and carefully explain the law of comparative advantage using simple numerical examples, as in the text. Both sections are crucial. Section 5 explains the law of comparative advantage and Section 6 establishes the link between trade theory and international finance. I find that the numerical explanations before the graphical analysis really helps the student to truly understand the law. The simple lawyer-secretary example should also render the law more immediately relevant to the student. I would also assign Problems 4-7.3. In the third lecture, I would cover Sections 7-9 and assign Problems 8-10.4. In the fourth lecture, I would Section 10 and go over problems 4-10. The appendixes could bemade optional for the more enterprising students in the class.Answer to Review Questions and Problems1. The mercantilists believed that the way for a nation to become rich and powerful was toexport more than it imported. The resulting export surplus would then be settled by an inflow of gold and silver and the more gold and silver a nation had, the richer and more powerful it was. Thus, the government had to do all in its power to stimulate the nation’s exports and discourage and restrict imports. However, since all nations could not simultaneously have an export surplus and the amount of gold and silver was fixed at any particular point in time, one nation could gain only at the expense of other nations. The mercantilists thus preached economic nationalism, believing that national interests were basically in conflict.Adam Smith, on the other hand, believed that free trade would make all nations better off.All of this is relevant today because many of the arguments made in favor of restrictinginternational trade to protect domestic jobs are very similar to the mercantilists argumentsmade three or four centuries ago. That is why we can say that “mercantilism is alive and well in the twenty-first century”. Thus we have to be prepared to answer and demonstrate thatthese arguments are basically wrong.2. According to Adam Smith, the basis for trade was absolute advantage, or one country being more productive or efficient in the production of some commodities and other countriesbeing more productive in the production of other commodities.The gains from trade arise as each country specialized in the production of the commodities in which it had an absolute advantage and importing those commodities in which the nation had an absolute disadvantage.Adam Smith believed in free trade and laissez-faire, or as little government interference with the economic system as possible. There were to be only a few exceptions to this policy of laissez-faire and free trade. One of these was the protection of industries important for national defense.3. Ricardo’s law of comparative advantage is superior to Smith’s theory of absolute advantage inthat it showed that even if a nation is less efficient than or has an absolute disadvantage in theproduction of all commodities with respect to the other nations, there is still a basis for beneficial trade for all nations.The gains from trade arise from the increased production of all commodities that arises wheneach country specializes in the production of and exports the commodities of its comparativeadvantage and imports the other commodities.A nation that is less efficient than others will be able to export the commodities of its compara-tive advantage by having its wages and other costs sufficiently lower than in other nations so asto make the commodities of its comparative advantage cheaper in terms of the same currencywith respect to the other nations.4. a. In case A, the United States has an absolute and a comparative advantage in wheat and theUnited Kingdom in cloth.In case B, the United States has an absolute advantage (so that the United Kingdom has anabsolute disadvantage) in both commodities.In case C, the United States has an absolute advantage in wheat but has neither an absoluteadvantage nor disadvantage in cloth.In case D, the United States has an absolute advantage over the United Kingdom in bothcommodities.b. In case A, the United States has a comparative advantage in wheat and the United Kingdomin cloth.In case B, the United States has a comparative advantage in wheat and the United Kingdomin cloth.In case C, the United States has a comparative advantage in wheat and the United Kingdomin cloth.In case D, the United States and the United Kingdom have a comparative advantage in neither commodities.5. a. The United States gains 1C.b. The United Kingdom gains 4C.c. 3C < 4W < 8C.d. The United States would gain 3C while the United Kingdom would gain 2C.6. a. The cost in terms of labor content of producing wheat is 1/4 in the United States and 1 in the United Kingdom, while the cost in terms of labor content of producing cloth is 1/3 in theUnited States and 1/2 in the United Kingdom.b. In the United States, Pw=$1.50 and Pc=$2.00.c. In the United Kingdom, Pw=£1.00 and Pc=£0.50.7. The United States has a comparative disadvantage in the production of textiles. Restrictingtextile imports would keep U.S. workers from eventually moving into industries in which the United States has a comparative advantage and in which wages are higher.8. Ricardo’s explanation of the law of comparative is unacceptable because it is based on the labor theory of value, which is not an acceptable theory of value.The explanation of the law of comparative advantage can be based on the opportunity costdoctrine, which is an acceptable theory of value.9. The production possibilities frontier reflects the opportunity costs of producing bothcommodities in the nation.The production possibilities frontier under constant costs is a (negatively sloped) straight line. The absolute slope of the production possibilities frontier reflects or gives the price of thecommodity plotted along the horizontal axis in relation to the commodity plotted along thevertical axis.10. a. See Figure 1.b. In the United States Pw/Pc=3/4, while in the United Kingdom, Pw/Pc=2.c. In the United States Pc/Pw=4/3, while in the United Kingdom Pc/Pw=1/2.d. See Figure 2.The autarky points are A and A' in the United States and the United Kingdom, respectively. The points of production with trade are B and B' in the United States and the UnitedKingdom, respectively.The points of consumption are E and E' in the United States and the United Kingdom,respectively. The gains from trade are shown by E > A for the U.S. and E' > A' for the U.K.Fig 1.1aU.K. Fig 1.1bFigure1Fig 1.2aFig 1.2bFigure2Multiple-Choice Questions1. The Mercantilists did not advocated:*a. free tradeb. stimulating the nation's exportsc. restricting the nations' importsd. the accumulation of gold by the nation2. According to Adam Smith, international trade was based on:*a. absolute advantageb. comparative advantagec. both absolute and comparative advantaged. neither absolute nor comparative advantage3. What proportion of international trade is based on absolute advantage?a. allb. most*c. somed. none4. The commodity in which the nation has the smallest absolute disadvantage is the commodityof its:a. absolute disadvantageb. absolute advantagec. comparative disadvantaged. comparative advantage5. If in a two-nation (A and B), two-commodity (X and Y) world, it is established that nationA has a comparative advantage in commodity X, then nationB must have:a. an absolute advantage in commodity Yb. an absolute disadvantage in commodity Yc. a comparative disadvantage in commodity Y*d. a comparative advantage in commodity Y6. If with one hour of labor time nation A can produce either 3X or 3Y while nation B canproduce either 1X or 3Y (and labor is the only input):a. nation A has a comparative disadvantage in commodity Xb. nation B has a comparative disadvantage in commodity Y*c. nation A has a comparative advantage in commodity Xd. nation A has a comparative advantage in neither commodity7. With reference to the statement in Question 6:a. Px/Py=1 in nation Ab. Px/Py=3 in nation Bc. Py/Px=1/3 in nation B*d. all of the above8. With reference to the statement in Question 6, if 3X is exchanged for 3Y:a. nation A gains 2X*b. nation B gains 6Yc. nation A gains 3Yd. nation B gains 3Y9. With reference to the statement of Question 6, the range of mutually beneficial trade between nation A and B is:a. 3Y < 3X < 5Yb. 5Y < 3X < 9Y*c. 3Y < 3X < 9Yd. 1Y < 3X < 3Y10. If domestically 3X=3Y in nation A, while 1X=1Y domestically in nation B:a. there will be no trade between the two nationsb. the relative price of X is the same in both nationsc. the relative price of Y is the same in both nations*d. all of the above11. Ricardo explained the law of comparative advantage on the basis of:*a. the labor theory of valueb. the opportunity cost theoryc. the law of diminishing returnsd. all of the above12. The Ricardian trade model has been empirically*a. verifiedb. rejectedc. not testedd. tested but the results were inconclusive13. The Ricardian model was tested empirically in terms of differences ina. relative labor productivities costs in various industries among nationsb. relative labor costs in various industries among nations*c. relative labor productivities and costs in various industries among nationsd. none of the above14. A difference in relative commodity prices between two nations can be based upon a difference in:a. factor endowmentsb. technologyc. tastes*d. all of the above15. In the trade between a small and a large nation:a. the large nation is likely to receive all of the gains from trade*b. the small nation is likely to receive all of the gains from tradec. the gains from trade are likely to be equally sharedd. we cannot say。
Ch02HullFund7eTestBank

Ch02HullFund7eTestBankTest Bank: Chapter 2Mechanics of Futures and Forward Markets1.Which of the following is true (circle one)(a)Both forward and futures contracts are traded on exchanges.(b)Forward contracts are traded on exchanges, but futures contracts are not.(c)Futures contracts are traded on exchanges, but forward contracts are not.(d)Neither futures contracts nor forward contracts are traded on exchanges.2.Which of the following is not true (circle one)(a)Futures contracts nearly always last longer than forward contracts(b)Futures contracts are standardized; forward contracts are not.(c)Delivery or final cash settlement usually takes place with forward contracts;the same is not true of futures contracts.(d)Forward contract usually have one specified delivery date; futures contractoften have a range of delivery dates.3.In the corn futures contract a number of different types of corn can be delivered(with price adjustments specified by the exchange) and there are a number ofdifferent delivery locations. Which of the following is true (circle one)(a)This flexibility tends increase the futures price.(b)This flexibility tends decrease the futures price.(c)This flexibility may increase and may decrease the futures price.(d)This has no effect on the futures price4. A company enters into a short futures contract to sell 50,000 units of a commodityfor 70 cents per unit. The initial margin is $4,000 and the maintenance margin is $3,000. What is the futures price per unit above which there will be a margin call?_ _ _ _ _ _5. A company enters into a long futures contract to buy 1,000 barrels of oil for $60per barrel. The initial margin is $6,000 and the maintenance margin is $4,000.What oil futures price will allow $2,000 to be withdrawn from the margin account?…6.On the floor of a futures exchange one futures contract is traded where both thelong and short parties are closing out existing positions. What is the resultantchange in the open interest? Circle one.(a)No change(b)Decrease by one(c)Decrease by two(d)Increase by one7.Who initiates delivery in a corn futures contract (circle one)(a)The party with the long position(b)The party with the short position(c)Either party(d)The exchange8.You sell one December gold futures contracts when the futures price is $1,010 perounce. Each contract is on 100 ounces of gold and the initial margin per contract that you provide is $2,000. The maintenance margin per contract is $1,500.During the next day the futures price rises to $1,012 per ounce. What is thebalance of your margin account at the end of the day? _ _ _ _ _ _9. A hedger takes a long position in an oil futures contract on November 1, 2009 tohedge an exposure on March 1, 2010. The initial futures price is $60. OnDecember 31, 1999 the futures price is $61. On March 1, 2010 it is $64. Thecontract is closed out on March 1, 2010. What gain is recognized in theaccounting year January 1 to December 31, 2010? Each contract is on 1000barrels of oil. _ _ _ _ _ _10.What is your answer to question 9 if the trader is a speculator rather than a hedger?_ _ _ _ _ _。
Ch02-01-关系模型、关系数据结构、关系完整性new

• 空值,表示尚未分配专业;
• 非空值,必须是专业关系中某个元组的专业号值。
2. 3 关系的完整性
(2) 参照完整性: 例2.9:学生(学号,姓名,性别,专业号,年龄) 课程(课程号,课程名) 选修(学号,课程号,成绩) 学号
学生关系
选修关系
课程号
课程关系
根据参照完整性,选修关系中的学号和课程号属性的可能取值:
在一个给定的应用领域中,所有实体及实体之间联系的关系的集合构成一个 关系数据库,关系数据库模式包括: (1)若干域的定义; (2)在这些域上定义的若干关系模式。
2.2 关系操作
关系模型由关系数据结构、关系操作集合、关系完整性约束三部分组成。
2.2.1 基本的关系操作
选择、投影、并、差、笛卡尔积
查询操作
Supervisor 张清枚 刘逸
Speciality 计算机 机械
Postgraduate 李勇 王敏 刘琛
2.1.2 关系模式
关系模式是型,关系是值。关系模式应刻画如下方面: (1) 关系是元组的集合,因此关系模式必须指明这些元组集合的结构。即它由 哪些属性构成,这些属性来自哪些域,以及属性与域之间的映像关系。 (2) 一个关系通常是由赋予它的元组语义来确定的,凡使该语义为真的笛卡尔 积中的元素全体就构成了该关系模式的关系。 现实世界的许多已有事实限定了关系模式所有可能的关系必须满足一定的完 整性约束条件,关系模式应当刻画出这些完整性约束条件。
其中每一个元素(d1, d2, …, dn)叫做一个n元组(n-tuple)或简称元组(tuple)。元素 中的每一个值di,叫做一个分量(Component)。
若Di为有限集,其基数为mi,则D1×D2×…×Dn的基数为: n M = ∏mi i=1
CH02-使用SSMS创建和管理数据库
第二章 使用SSMS创建和 管理数据库
预习检查
什么是数据库登录名、数据库用户? 创建数据库需要指定哪两种文件?
使用T-SQL语句创建数据库的语法是什么?
写出删除数据库的SQL语句 为什么要备份数据库?
本章目标
掌握SSMS的基本操作。
能够使用SSMS图形工具创建、配置、管理和维护SQL
系统数据库和用户数据库
master model tempdb msdb Resource
系统数据库
SchoolDB
Pubs
NorthWind
……
用户数据库
系统数据库
1.master数据库 master数据库记录SQL Server中 所有系统级别的信息,包括所有登录账户、系统配 置和设置、服务器中其他数据库的相关信息和这些 数据库文件的位置,以及SQL Server初始化信息等。 2. model数据库 model数据库用于创建所有数据库 的模板,是tempdb数据库的基础。例如,使用SQL 语句创建新数据库时,将使用模板中规定的默认值 来创建。 3.tempdb数据库 tempdb数据库是一个临时性的数 据库,保存所有的临时表和临时存储过程,以及临 时工作表。关闭SQL Server服务时,tempdb数据库 保存的内容将自动消失,重新启动SQL Server服务 时,系统将重新创建空的tempdb数据库。
operating system操作系统-ch02-operating-system structures-42 共42页
2.3 System Calls
Programming interface to the services provided by the OS Typically written in a high-level language (C or C++) Mostly accessed by programs via a high-level Application
I/O operations - A running program may require I/O, which may involve a file or an I/O device.
File-system manipulation - The file system is of particular interest. Obviously, programs need to read and write files and directories, create and delete them, search them, list file Information, permission management.
Why use APIs rather than system calls? Program portability/convenience/
2.10
Example of Standard API
Consider the ReadFile() function in the Win32 API—a function for reading from a file
2.5
Operating System Services (Cont.)
Another set of OS functions exists for ensuring the efficient operation of the system itself via resource sharing Resource allocation - When multiple users or multiple jobs running concurrently, resources must be allocated to each of them Many types of resources - Some (such as CPU cycles,mainmemory, and file storage) may have special allocation code, others (such as I/O devices) may have general request and release code. Accounting - To keep track of which users use how much and what kinds of computer resources Protection and security - The owners of information stored in a multiuser or networked computer system may want to control use of that information, concurrent processes should not interfere with each other Protection involves ensuring that all access to system resources is controlled Security of the system from outsiders requires user authentication, extends to defending external I/O devices from invalid access attempts If a system is to be protected and secure, precautions must be instituted throughout it. A chain is only as strong as its weakest link.
CH02 Labor productivity comparative advantage the Ricardian model(国际经济学-厦门大学 陈涛)
• Roses have lower opportunity costs in South America. • Computers have lower opportunity costs in the U.S.
The benefits from trade can be seen by considering
•
• From our previous example, we get:
QC + 2QW = 120
Copyright © 2003 Pearson Education, Inc.
Slide 1-12
A One-Factor Economy
Figure 2-1: Home’s Production Possibility Frontier
CHAPTER 2
LABOR PRODUCTIVITY COMPARATIVE ADVANTAGE THE RICARDIAN MODEL
Chapter Organization
Introduction The Concept of Comparative Advantage A One-Factor Economy Trade in a One-Factor World Comparative Advantage with Many Goods Adding Transport Costs and Nontraded Goods Summary
计算机二级accessch02VBA实例
Private sub Command1_click( ) Dim x as integer, y as integer x=12:y=32 call p(x,y) Msgbox x*y
Endsub Public Sub p(n as integer,ByVal m as integer)
容为 21isoddnumber
A
VBA上机
• 题型:数学问题或窗体设计 • 牢记几个事件的代码 • 牢记常用外观属性的名称 • 例题:设计一窗体,含一命令按钮,窗体
打开时,该按钮不可用。
VBA上机
• 常用事件
– 单击:private sub 对象_click() – 打开窗口: private sub form_open(cancel
A、1和1
B、1.25和1
C、1.25和4 D、5和4
B
• 程序运行结果是 。
• Function Fact(n As Integer) As Long
• Dim i As Integer, s As Long
• s=1
• For i = 1 To n
•
s=s*i
• Next
• Fact = s
• End Function
• Area r
: Debug.Print r
• End Sub
在窗体中添加一个命令按钮(名称为Command1),然后编写如 下代码:
Public x as integer
Private Sub Command1_Click( )
X=10
Call s1
Call s2
MsgBox x End Sub Private Sub s1( )
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
数据类型转换
• 隐式转换:只允许发生在从小的值范围 的类型到大的值范围的类型的转换,转 换后的数值大小不受影响 • 显式转换(强制转换):将表达式强制 转换为所需的数据类型 • 表2-15 Convert类提供的类型转换方法 • 使用关键字checked可以指定已检查的上 下文;使用关键字unchecked可以指定未 检查的上下文 • 【例2.9】checked关键字使用示例
2.2 表达式
• 表达式由操作数(变量、常量、函数)、运算符和圆 括号构成 • 表达式的书写规则
– (1)乘号不能省略,例如,a乘以b应写为a*b – (2)括号必须成对出现,而且只能使用圆括号;圆括号可以嵌套使用 – (3)表达式从左到右在同一个基准上书写,无高低、大小区分
• 例如:数学表达式 写成C#表达式为:Math.sin(a*x + b)/2
– C#定义的关键字不能用作变量名,但可以定义 @加关键字的变量名
• C#语言一般遵循两种命名约定:PascalCase 和camelCase • 声明变量: 变量类型 变量名; • 变量赋值: 变量 = 要赋的值; • 【例2.1】变量的声明和赋值示例( T2VarDeclare.cs)
变量和常量
• 简单赋值语句:变量名 = 表达式; • 表2-1 C#中的复合赋值运算符
– “x += y”等效于“x = x + y”,但是,“x += y”中x只计算一次
• 文本常量:代码中出现的文本形式常数 • 用户声明常量:变量前加关键字const • 【例2.2】常量的声明和赋值示例( T2Const.cs)
第2章 C#语言基础
• • • • • • 语句、表达式和运算符 变量和常量 数据类型 数值数据类型和算术运算 字符类型 数据类型转换
2.1 语句
• 通常以分号终止 • 由花括号({和})括起来的代码块
– – – – – – – 声明语句:用于声明局部变量和常量 表达式语句:用于对表达式求值 选择语句:if和switch语句 迭代语句:while、do、for和foreach 跳转语句:break、continue、goto、return和throw语句 try...catch...finally语句:捕获在块的执行期间发生的异常 checked/unchecked语句:控制整型算术运算和转换的溢出检查 上下文 – lock语句:获取某个给定对象的互斥锁,执行一个语句,然后 释放该锁 – using语句:获得一个资源,执行一个语句,然后释放该资源
• 【例2.4】装箱和拆箱示例( T2BoxUnbox.cs)
数值数据类型和算术运算(1)
• • • • • • • • • 整型、浮点类型和decimal类型 表2-3 预定义整数类型 表2-4 整型常量 【例2.5】整型变量示例:十进制到十六进制 的数制转换 表2-5 浮点数据类型(float和double) 【例2.6】浮点类型变量示例 表2-6 decimal数据类型 【例2.7】decimal类型变量示例 表2-7 算术运算符
数值数据类型和算术运算(2)
• • • • • • • • 表2-8 Math类的2个公共字段 表2-9 Math类常用函数(静态方法) 表2-10 Random类随机方法 表2-11 位运算符 表2-12 char数据类型 表2-13 特殊符号的转义序列 表2-14 System.Char主要成员 【例2.8】字符类型变量示例
• 接受一个操作数的运算符被称作一元运算符,例如增 量运算符(++)或new • 接受两个操作数的运算符被称作二元运算符,例如算 术运算符+、-、*、/等 • 接受三个操作数的运算符被称作三元运算符,条件运 算符“?:”是C#中唯一的三元运算符
2.4 变量(1)
• 标识符的第一个字符必须是字母、下划线( “_”)或@,其后的字符可以是字母、下 划线或数字
实验和习题
• 实验2-1~实验2-6
• 2.10 复习题
– 单选题 – 填空题 – 思考题
• 【例2.3】值类型与引用类型之间的区别示例 (T2ValRefType.cs) • 图2-1 值类型与引用类型内存分配示意图
装箱和拆箱
• 值类型和引用类型之间的转换 • 装箱转换
– 将值类型隐式或显式地转换成一个object类 型,或者把这个值类型转换成被
– 将对象类型显式地转换成值类型,或是将接 口类型显式地转换成执行该接口的值类型
2.6 数据类型
值类型和引用类型
• 值类型变量在堆栈(Stack)中直接包含其数 据,每个变量都有自己的数据副本
– 简单类型、枚举类型、结构类型,null类型
• 引用类型变量在堆栈(Stack)中存储对数据 (对象)的引用(地址),两个变量可能引用 同一个对象
– 类类型、接口类型、数组类型和委托类型