13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 8 <strong>Language</strong> Overview}}}case Color.Green:…break;default:break;shows a Color enum and a method that uses this enum. The signature of the Fill method makes it clearthat the shape can be filled with one of the given colors.The use of enums is superior to the use of integer constants—as is common in languages without enums—because the use of enums makes the code more readable and self-documenting. The self-documenting natureof the code also makes it possible for the development tool to assist with code writing and other “designer”activities. For example, the use of Color rather than int for a parameter type enables smart code editors tosuggest Color values.8.12 Namespaces and assembliesThe programs presented so far have stood on their own except for dependence on a few system-providedclasses such as System.Console. It is far more common, however, for real-world applications to consist ofseveral different pieces, each compiled separately. For example, a corporate application might depend onseveral different components, including some developed internally and some purchased from independentsoftware vendors.Namespaces and assemblies enable this component-based system. Namespaces provide a logicalorganizational system. Namespaces are used both as an “internal” organization system for a program, and asan “external” organization system—a way of presenting program elements that are exposed to otherprograms.Assemblies are used for physical packaging and deployment. An assembly may contain types, the executablecode used to implement these types, and references to other assemblies.To demonstrate the use of namespaces and assemblies, this section revisits the “hello, world” programpresented earlier, and splits it into two pieces: a class library that provides messages and a consoleapplication that displays them.The class library will contain a single class named HelloMessage. The example// HelloLibrary.csnamespace CSharp.Introduction{public class HelloMessage}{}public string Message {get {return "hello, world";}}shows the HelloMessage class in a namespace named CSharp.Introduction. The HelloMessageclass provides a read-only property named Message. Namespaces can nest, and the declarationnamespace CSharp.Introduction{…}is shorthand for two levels of namespace nesting:namespace CSharp{namespace Introduction}{…}45

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!