fulltext_012

上传人:小** 文档编号:47490518 上传时间:2018-07-02 格式:PDF 页数:70 大小:416.95KB
返回 下载 相关 举报
fulltext_012_第1页
第1页 / 共70页
fulltext_012_第2页
第2页 / 共70页
fulltext_012_第3页
第3页 / 共70页
fulltext_012_第4页
第4页 / 共70页
fulltext_012_第5页
第5页 / 共70页
点击查看更多>>
资源描述

《fulltext_012》由会员分享,可在线阅读,更多相关《fulltext_012(70页珍藏版)》请在金锄头文库上搜索。

1、A Deeper Look at C#Were almost ready to develop the Student Registration System (SRS) application in C#, based on the UML model that we created in Part Two. Before we dive into the specifics of cod- ing the SRS, however, there are a number of additional C# language features that we want to cover, ma

2、ny of which well put to use in building the SRS. Realize that we cant do justice to all of the remaining features of the C# language in just one chapter; C# is an extremely rich language, and most good C# references are many hun- dreds of pages long. Our goal isnt to duplicate the hard work that has

3、 gone into existing C# reference books, but instead to complement them by showing you how to bridge the gap between producing an object model and turning it into C# codesomething that few, if any, other books do. With that in mind, well be selective in terms of which aspects of the C# language we in

4、troduce in this chapter: namely, those that are most critical to understanding the SRS coding examples that follow in Chapters 14 through 16. Nonetheless, youll have gone from “concept to code” and will acquire a very respectable working knowledge of C# by the time that weve finished.TipEven if youv

5、e already been programming in C# for a while, and thus feel that you have a fairly good grasp of the language syntax, we encourage you to at least skim this chapter before moving on to Chapter 14 because well mention a few things along the way with regard to how well be approaching the SRS.In this c

6、hapter, youll learn about the following: The C# notion of namespaceshow to define them and why we use them The object nature of a string, and some of the methods/properties provided to manip- ulate them The Object class, a predefined class that is the ultimate base class of every C# type Using a spe

7、cial keyword, this, to “self-reference” an object from within one of its own methods The object nature of arrays and some of the methods/properties provided to manipu- late them The List and Dictionary classes, two of the .NET Framework generic collection classes339C H A P T E R 1 3 The nature of ob

8、ject identities in C#, how to discover the true class that an object belongs to, and how to test the equality of two C# objects Important variants on the Main method and the base keyword How auto-implemented properties can be used to simplify code listings How dynamically created objects are deleted

9、 to recycle their memory and the role that the common language runtime (CLR) garbage collector plays in this recycling A .NET Framework language construct called an attribute Well also revisit some of the topics that we introduced in earlier chapters to provide you with additional insights.Namespace

10、sThroughout the examples in Parts One and Two of this book, and in most of the examples to follow, weve commonly placed a using statement (more formally referred to as a using direc- tive) at the top of our programs to allow us to access the elements of a particular namespace by their simple names.

11、By way of review, a namespace is a logical grouping of related program- ming elements, as was briefly discussed in Chapter 1; the .NET Framework libraries are so vast that namespaces are used to divide the libraries up into more manageable sublibraries. A simple name is the name of the class as it a

12、ppears in the class declaration; for example:/ This class has the simple name “Student“. public class Student / Details omitted. When a class is placed inside a namespace, its name “changes” in that it acquires its namespace as part of its fully qualified name. For example, as discussed earlier in t

13、he book, because the String class is contained in the System namespace, the fully qualified name of the class is System.String; the simple name of the class remains String. Its conceivable that two classes that belong to two different namespaces A and B could be given the same simple name X, just as

14、, by way of analogy, its possible to create two different Microsoft Word documents with the same name (for example, xyz.doc) as long as they are located in different Windows folders (for example, C:MyDocs and D:Stuff). When we fully qualify the names of such like-named classesA.X and B.Xthese names

15、are guaranteed to be unique, just as in the Word document analogy, the two like-named documents in our example would have different fully qualified file names; for example, C:MyDocsxyz.doc and D:Stuffxyz.doc. To be absolutely certain that the compiler knows which class we want to use in any given si

16、tuation, we could always use fully qualified class names in our program:/ Note that weve provided no “using“ directives / with this program.public class SimpleProgram3 CHAPTER 13 A DEEPER LOOK AT C#340static void Main() System.String name = “Jackson“; System.Console.WriteLine(“The name is “ + name); Having to type the fully qualified name of every namespace member that were using in a program is cumbersome, however, and makes for less readab

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 商业/管理/HR > 经营企划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号