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

📄 chapter 9.mht

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

This is a multi-part message in MIME format.

------=_NextPart_000_004B_01C7EA40.99FC8C20
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://www.vijaymukhi.com/documents/books/csadv/chap9.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>Miscellaneous - 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"./Chap9_files/filelist.xml" rel=3DFile-List><LINK=20
href=3D"./Chap9_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>1</o:TotalTime>
  <o:Created>2001-09-27T12:20:00Z</o:Created>
  <o:LastSaved>2001-09-27T12:21:00Z</o:LastSaved>
  <o:Pages>19</o:Pages>
  <o:Words>4591</o:Words>
  <o:Characters>26173</o:Characters>
  <o:Company>V.M.C.I.</o:Company>
  <o:Lines>218</o:Lines>
  <o:Paragraphs>52</o:Paragraphs>
  <o:CharactersWithSpaces>32142</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.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
9</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">Miscellaneous</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">Members<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=3DCbase><SPAN style=3D"COLOR: windowtext">There are only two =
types of=20
entities that can contain members, namely, types and namespaces. These =
members=20
can be accessed using the same rules i.e. the name of an entity to be =
followed=20
by a dot '.' and then the member name to be given. This cardinal rule is =
never=20
ever broken. <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">All derived classes =
inherit every=20
member of a base class with the exception of constructors and =
destructors. This=20
rule applies to private members also. Regardless of inheriting all the =
members,=20
the base class members may/may not be accessible to the derived class =
members.=20
Thus, the access modifiers have nothing to contribute to inheritance. In =
other=20
words, the rules of inheritance ignore the access=20
modifiers.<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">If a namespace is not =
specified=20
for a member, it belongs to a default namespace called the global =
namespace.=20
Like it or not, all members are part and parcel of a namespace. They =
cannot=20
exist out of a namespace under any circumstance. It makes logical sense =
creating=20
our own namespaces thereby avoiding the unnecessary clutter in the =
global=20
namespace with the members we create.<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">The word int is an =
alias for=20
System.Int32. A variable of type int is internally known as =
System.Int32. The=20
basic types like int are internally not known by their name but =
something else=20
that is entirely different.<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>public 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>System.Type t =3D typeof(int);<o:p></o:p></P>
<P class=3DCprg>System.Console.WriteLine(t.FullName);<o:p></o:p></P>
<P class=3DCprg>}<o:p></o:p></P>
<P class=3DCprg>}<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=3DCoutput><U>Output</U><o:p></o:p></P>
<P class=3DCoutput>System.Int32<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">The above example =
reconfirms the=20
point we enumerated a little earlier. The compiler does not understand =
an int as=20
a data type but knows all about a structure called System.Int32 instead. =
When we=20
coached you earlier about the compiler understanding about data types =
like int=20
at birth, what we truly meant was that there exists structures in the =
System=20
namespace relating to these datatypes. The compiler is informed well in =
advance=20
about the one-to-one connection between the alias name and their =
structures.=20
When we get some time on our hand, we will list out and explain all the =
members=20
of this structure. <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">To explain the above =
example, we=20
use a keyword typeof, which accepts the name of a class or structure. =
This=20
returns an object that looks like Type. The Type object consists of =
methods and=20
properties that publish everything you ever wanted to know about a type =
but were=20
afraid to ask. We are only using one member called FullName to prove our =

hypothesis. <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<SPAN style=3D"mso-spacerun: =
yes">&nbsp;=20
</SPAN>Main()<o:p></o:p></P>
<P class=3DCprg>{<o:p></o:p></P>
<P class=3DCprg>string yyy =3D "hell";<o:p></o:p></P>
<P class=3DCprg>string s =3D yyy;<o:p></o:p></P>
<P class=3DCprg>System.Type t =3D typeof(yyy);<o:p></o:p></P>
<P class=3DCprg>System.Console.WriteLine(s);<o:p></o:p></P>
<P class=3DCprg>System.Console.WriteLine(t);<o:p></o:p></P>
<P class=3DCprg>}<o:p></o:p></P>
<P class=3DCprg>}<o:p></o:p></P>
<P class=3DCprg>class yyy<o:p></o:p></P>
<P class=3DCprg>{<o:p></o:p></P>
<P class=3DCprg>}<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=3DCoutput><U>Output</U><o:p></o:p></P>
<P class=3DCoutput>hell<o:p></o:p></P>

⌨️ 快捷键说明

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