Get 20M+ Full-Text Papers For Less Than $1.50/day. Start a 14-Day Trial for You or Your Team.

Learn More →

A Programmer’s Introduction to C# 2.0Other Class Details

A Programmer’s Introduction to C# 2.0: Other Class Details CHAPTER 8 ■ ■ ■ T his chapter discusses some of the miscellaneous issues of classes, including constructors, nesting, and overloading rules. Nested Classes Sometimes it’s convenient to nest classes within other classes, such as when a helper class is used by only one other class. The accessibility of the nested class follows similar rules to the ones outlined in Chapter 7 for the interaction of class and member modifiers. As with members, the accessibility modifier on a nested class defines what accessibility the nested class has outside the nested class. Just as a private field is visible only within a class, a private nested class is also visible only from within the class that contains it. In the following example, the Parser class has a Token class that it uses internally. Without using a nested class, it might be written as follows: public class Parser Token[] tokens; public class Token string name; In this example, both the Parser and Token classes are publicly accessible, which isn’t optimal. Not only is the Token class one more class taking up space in the designers that list classes, but it isn’t designed to be generally useful. It’s therefore helpful to make http://www.deepdyve.com/assets/images/DeepDyve-Logo-lg.png

A Programmer’s Introduction to C# 2.0Other Class Details

Editors: Gunnerson, Eric; Wienholt, Nick

Loading next page...
 
/lp/springer-journals/a-programmer-s-introduction-to-c-2-0-other-class-details-WBZ02QSuM9

References (0)

References for this paper are not available at this time. We will be adding them shortly, thank you for your patience.

Publisher
Apress
Copyright
© Apress 2005
ISBN
978-1-59059-501-5
Pages
61 –77
DOI
10.1007/978-1-4302-0035-2_8
Publisher site
See Chapter on Publisher Site

Abstract

CHAPTER 8 ■ ■ ■ T his chapter discusses some of the miscellaneous issues of classes, including constructors, nesting, and overloading rules. Nested Classes Sometimes it’s convenient to nest classes within other classes, such as when a helper class is used by only one other class. The accessibility of the nested class follows similar rules to the ones outlined in Chapter 7 for the interaction of class and member modifiers. As with members, the accessibility modifier on a nested class defines what accessibility the nested class has outside the nested class. Just as a private field is visible only within a class, a private nested class is also visible only from within the class that contains it. In the following example, the Parser class has a Token class that it uses internally. Without using a nested class, it might be written as follows: public class Parser Token[] tokens; public class Token string name; In this example, both the Parser and Token classes are publicly accessible, which isn’t optimal. Not only is the Token class one more class taking up space in the designers that list classes, but it isn’t designed to be generally useful. It’s therefore helpful to make

Published: Jan 1, 2005

There are no references for this article.