⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chapter 7.mht

📁 C# Nuts and Bolt是学习C#的极好教程
💻 MHT
📖 第 1 页 / 共 5 页
字号:
From: <Saved by Microsoft Internet Explorer 5>
Subject: Operators - C# Nuts and Bolt - Beta2
Date: Wed, 29 Aug 2007 13:28:55 +0800
MIME-Version: 1.0
Content-Type: multipart/related;
	type="text/html";
	boundary="----=_NextPart_000_0041_01C7EA40.8C8C25F0"
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138

This is a multi-part message in MIME format.

------=_NextPart_000_0041_01C7EA40.8C8C25F0
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://www.vijaymukhi.com/documents/books/csadv/chap7.htm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns=3D"http://www.w3.org/TR/REC-html40" xmlns:v =3D=20
"urn:schemas-microsoft-com:vml" xmlns:o =3D=20
"urn:schemas-microsoft-com:office:office" xmlns:w =3D=20
"urn:schemas-microsoft-com:office:word"><HEAD><TITLE>Operators - C# Nuts =
and Bolt - Beta2</TITLE>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3DWord.Document name=3DProgId>
<META content=3D"MSHTML 6.00.2900.3157" name=3DGENERATOR>
<META content=3D"Microsoft Word 9" name=3DOriginator><LINK=20
href=3D"./Chap7_files/filelist.xml" rel=3DFile-List><LINK=20
href=3D"./Chap7_files/editdata.mso" rel=3DEdit-Time-Data><!--[if !mso]>
<STYLE>v\:* {
	BEHAVIOR: url(#default#VML)
}
o\:* {
	BEHAVIOR: url(#default#VML)
}
w\:* {
	BEHAVIOR: url(#default#VML)
}
.shape {
	BEHAVIOR: url(#default#VML)
}
</STYLE>
<![endif]--><!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>Vijay Mukhi</o:Author>
  <o:LastAuthor>Vijay Mukhi</o:LastAuthor>
  <o:Revision>1</o:Revision>
  <o:TotalTime>2</o:TotalTime>
  <o:Created>2001-09-27T12:17:00Z</o:Created>
  <o:LastSaved>2001-09-27T12:19:00Z</o:LastSaved>
  <o:Pages>60</o:Pages>
  <o:Words>15631</o:Words>
  <o:Characters>89097</o:Characters>
  <o:Company>V.M.C.I.</o:Company>
  <o:Lines>742</o:Lines>
  <o:Paragraphs>178</o:Paragraphs>
  <o:CharactersWithSpaces>109417</o:CharactersWithSpaces>
  <o:Version>9.2720</o:Version>
 </o:DocumentProperties>
</xml><![endif]-->
<STYLE>@font-face {
	font-family: Tahoma;
}
@font-face {
	font-family: Trebuchet MS;
}
@font-face {
	font-family: Bookman Old Style;
}
@font-face {
	font-family: Garamond;
}
@page Section1 {size: 8.5in 11.0in; margin: 1.0in 1.25in 1.0in 1.25in; =
mso-header-margin: .5in; mso-footer-margin: .5in; mso-paper-source: 0; }
P.MsoNormal {
	FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"; =
mso-style-parent: ""; mso-pagination: widow-orphan; =
mso-fareast-font-family: "Times New Roman"
}
LI.MsoNormal {
	FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"; =
mso-style-parent: ""; mso-pagination: widow-orphan; =
mso-fareast-font-family: "Times New Roman"
}
DIV.MsoNormal {
	FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"; =
mso-style-parent: ""; mso-pagination: widow-orphan; =
mso-fareast-font-family: "Times New Roman"
}
P.Cprg {
	FONT-SIZE: 9.5pt; MARGIN: 0in 0in 0pt 0.5in; FONT-FAMILY: "Trebuchet =
MS"; mso-style-parent: "C#base"; mso-pagination: widow-orphan; =
mso-fareast-font-family: "Times New Roman"; mso-style-name: "C#prg"; =
mso-layout-grid-align: none; mso-bidi-font-family: "Times New Roman"
}
LI.Cprg {
	FONT-SIZE: 9.5pt; MARGIN: 0in 0in 0pt 0.5in; FONT-FAMILY: "Trebuchet =
MS"; mso-style-parent: "C#base"; mso-pagination: widow-orphan; =
mso-fareast-font-family: "Times New Roman"; mso-style-name: "C#prg"; =
mso-layout-grid-align: none; mso-bidi-font-family: "Times New Roman"
}
DIV.Cprg {
	FONT-SIZE: 9.5pt; MARGIN: 0in 0in 0pt 0.5in; FONT-FAMILY: "Trebuchet =
MS"; mso-style-parent: "C#base"; mso-pagination: widow-orphan; =
mso-fareast-font-family: "Times New Roman"; mso-style-name: "C#prg"; =
mso-layout-grid-align: none; mso-bidi-font-family: "Times New Roman"
}
P.Coutput {
	FONT-SIZE: 9.5pt; MARGIN: 0in 0in 0pt 0.5in; FONT-FAMILY: "Trebuchet =
MS"; mso-style-parent: "C#base"; mso-pagination: widow-orphan; =
mso-fareast-font-family: "Times New Roman"; mso-style-name: "C#output"; =
mso-layout-grid-align: none; mso-bidi-font-family: "Times New Roman"
}
LI.Coutput {
	FONT-SIZE: 9.5pt; MARGIN: 0in 0in 0pt 0.5in; FONT-FAMILY: "Trebuchet =
MS"; mso-style-parent: "C#base"; mso-pagination: widow-orphan; =
mso-fareast-font-family: "Times New Roman"; mso-style-name: "C#output"; =
mso-layout-grid-align: none; mso-bidi-font-family: "Times New Roman"
}
DIV.Coutput {
	FONT-SIZE: 9.5pt; MARGIN: 0in 0in 0pt 0.5in; FONT-FAMILY: "Trebuchet =
MS"; mso-style-parent: "C#base"; mso-pagination: widow-orphan; =
mso-fareast-font-family: "Times New Roman"; mso-style-name: "C#output"; =
mso-layout-grid-align: none; mso-bidi-font-family: "Times New Roman"
}
P.Cbullets {
	FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt 0.3in; FONT-FAMILY: "Bookman Old =
Style"; TEXT-ALIGN: justify; mso-style-parent: ""; mso-pagination: =
widow-orphan; mso-fareast-font-family: "Times New Roman"; =
mso-style-name: "C#bullets"; mso-layout-grid-align: none; =
mso-bidi-font-family: "Times New Roman"
}
LI.Cbullets {
	FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt 0.3in; FONT-FAMILY: "Bookman Old =
Style"; TEXT-ALIGN: justify; mso-style-parent: ""; mso-pagination: =
widow-orphan; mso-fareast-font-family: "Times New Roman"; =
mso-style-name: "C#bullets"; mso-layout-grid-align: none; =
mso-bidi-font-family: "Times New Roman"
}
DIV.Cbullets {
	FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt 0.3in; FONT-FAMILY: "Bookman Old =
Style"; TEXT-ALIGN: justify; mso-style-parent: ""; mso-pagination: =
widow-orphan; mso-fareast-font-family: "Times New Roman"; =
mso-style-name: "C#bullets"; mso-layout-grid-align: none; =
mso-bidi-font-family: "Times New Roman"
}
P.Cbase {
	FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt; COLOR: black; FONT-FAMILY: =
"Bookman Old Style"; TEXT-ALIGN: justify; mso-style-parent: ""; =
mso-pagination: widow-orphan; mso-fareast-font-family: "Times New =
Roman"; mso-style-name: "C#base"; mso-layout-grid-align: none; =
mso-bidi-font-family: "Times New Roman"
}
LI.Cbase {
	FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt; COLOR: black; FONT-FAMILY: =
"Bookman Old Style"; TEXT-ALIGN: justify; mso-style-parent: ""; =
mso-pagination: widow-orphan; mso-fareast-font-family: "Times New =
Roman"; mso-style-name: "C#base"; mso-layout-grid-align: none; =
mso-bidi-font-family: "Times New Roman"
}
DIV.Cbase {
	FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt; COLOR: black; FONT-FAMILY: =
"Bookman Old Style"; TEXT-ALIGN: justify; mso-style-parent: ""; =
mso-pagination: widow-orphan; mso-fareast-font-family: "Times New =
Roman"; mso-style-name: "C#base"; mso-layout-grid-align: none; =
mso-bidi-font-family: "Times New Roman"
}
DIV.Section1 {
	page: Section1
}
</STYLE>
</HEAD>
<BODY lang=3DEN-US style=3D"tab-interval: .5in">
<DIV class=3DSection1>
<P class=3DMsoNormal><IMG id=3D_x0000_i1025 height=3D48=20
src=3D"http://www.vijaymukhi.com/documents/books/csadv/bpb.jpg" =
width=3D64></P>
<P class=3DMsoNormal><![if =
!supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></P>
<P class=3DMsoNormal><SPAN=20
style=3D"FONT-SIZE: 15pt; COLOR: black; FONT-FAMILY: Garamond">Chapter=20
7</SPAN></P>
<P class=3DMsoNormal><![if =
!supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></P>
<P class=3DMsoNormal><SPAN=20
style=3D"FONT-SIZE: 26pt; COLOR: black; FONT-FAMILY: =
Garamond">Operators</SPAN></P>
<P class=3DCbase><SPAN style=3D"COLOR: windowtext"><![if =
!supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></SPAN></P>
<P class=3DCbase><SPAN style=3D"COLOR: windowtext">We all like to =
express ourselves=20
in different ways. Some smile, some laugh, some screech and some even =
shout. The=20
C# programming language lays a lot of emphasis on expressions and has =
one of the=20
largest chapters in its documentation devoted to it. An expression is a =
sequence=20
of operators and operands providing some computational activity.=20
<o:p></o:p></SPAN></P>
<P class=3DCbase><SPAN style=3D"COLOR: windowtext"><![if =
!supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></SPAN></P>
<P class=3DCbase><SPAN style=3D"COLOR: windowtext">An expression can be =
built in n=20
number of ways. It can be as simple as a value resulting in a certain =
type. It=20
can also consist of a variable with a type. A namespace can also occur =
in an=20
expression but it must be only at the beginning. A type like a namespace =
can=20
also occur on the left hand side of an expression. The usual gang of =
idiots like=20
properties, indexers, properties can also be included in an expression. =
However,=20
the final result of an expression can never ever be a namespace, type, =
method=20
group or event access. These can only occur in intermediate results.=20
<o:p></o:p></SPAN></P>
<P class=3DCbase><SPAN style=3D"COLOR: windowtext"><![if =
!supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></SPAN></P>
<P class=3DCbase><SPAN style=3D"COLOR: windowtext">Expressions are not =
conjured out=20
of thin air but are made up of only two entities, operators and what we =
offer=20
them in homage, operands. Operands can include constants, variables, =
indexers=20
etc. The second entity, operators is what this chapter is dedicated=20
to.<o:p></o:p></SPAN></P>
<P class=3DCbase><SPAN style=3D"COLOR: windowtext"><![if =
!supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></SPAN></P>
<P class=3DCbase><B><SPAN=20
style=3D"FONT-SIZE: 14pt; COLOR: windowtext; FONT-FAMILY: Tahoma"><![if =
!supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></SPAN></B></P>
<P class=3DCbase><B><SPAN=20
style=3D"FONT-SIZE: 14pt; COLOR: windowtext; FONT-FAMILY: =
Tahoma">Checked and=20
Unchecked Operators<o:p></o:p></SPAN></B></P>
<P class=3DCbase><SPAN style=3D"COLOR: windowtext"><![if =
!supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></SPAN></P>
<P class=3DCprg><U>a.cs</U><o:p></o:p></P>
<P class=3DCprg>class zzz<o:p></o:p></P>
<P class=3DCprg>{<o:p></o:p></P>
<P class=3DCprg>byte i =3D 255;<o:p></o:p></P>
<P class=3DCprg>byte j =3D 256;<o:p></o:p></P>
<P class=3DCprg>public static void Main()<o:p></o:p></P>
<P class=3DCprg>{<o:p></o:p></P>
<P class=3DCprg>byte k =3D -1;<o:p></o:p></P>
<P class=3DCprg>}<o:p></o:p></P>
<P class=3DCprg>}<o:p></o:p></P>
<P class=3DCprg><![if =
!supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></P>
<P class=3DCoutput><U>Compiler Error</U><o:p></o:p></P>
<P class=3DCoutput>a.cs(7,10): error CS0031: Constant value '-1' cannot =
be=20
converted to a 'byte'<o:p></o:p></P>
<P class=3DCoutput>a.cs(4,10): error CS0031: Constant value '256' cannot =
be=20
converted to a 'byte'<o:p></o:p></P>
<P class=3DCbase><SPAN style=3D"COLOR: windowtext"><![if =
!supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></SPAN></P>
<P class=3DCbase><SPAN style=3D"COLOR: windowtext">A byte can only store =
values from=20
0 to 255. We have initialized i to the largest possible value a byte can =
store=20
i.e. 255. For the second variable, we try and go beyond the range that a =
byte=20
can handle. Well, the compiler comes back screaming at us with an error. =
This is=20
the behaviour in the case of variable j. This is enough proof that the =
compiler=20
checks the values, the variables are being initialized to. For that =
matter, it=20
could be a local variable created in a function or an instance variable =
created=20
out of a function. Come what may, C# does not allow you to take a byte =
and give=20
it a value falling outside its range of 0 to 255.<o:p></o:p></SPAN></P>
<P class=3DCbase><SPAN style=3D"COLOR: windowtext"><![if =
!supportEmptyParas]><![endif]>&nbsp;<o:p></o:p></SPAN></P>
<P class=3DCprg><U>a.cs</U><o:p></o:p></P>
<P class=3DCprg>class zzz<o:p></o:p></P>
<P class=3DCprg>{<o:p></o:p></P>
<P class=3DCprg>public static void Main() <o:p></o:p></P>
<P class=3DCprg>{<o:p></o:p></P>
<P class=3DCprg>byte k =3D (byte)256;<o:p></o:p></P>
<P class=3DCprg>byte l =3D (byte)257;<o:p></o:p></P>
<P class=3DCprg>byte m =3D (byte)514;<o:p></o:p></P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -