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.

<strong>C#</strong> LANGUAGE SPECIFICATIONThe next step in the componentization of “hello, world” is to write a console application that uses theHelloMessage class. The fully qualified name for the class—CSharp.Introduction.HelloMessage—could be used, but this name is quite long and unwieldy. Aneasier way is to use a using namespace directive, which makes it possible to use all of the types in anamespace without qualification. The example// HelloApp.csusing CSharp.Introduction;class HelloApp{static void Main() {HelloMessage m = new HelloMessage();System.Console.WriteLine(m.Message);}}shows a using namespace directive that refers to the CSharp.Introduction namespace. The occurrencesof HelloMessage are shorthand for CSharp.Introduction.HelloMessage.<strong>C#</strong> also enables the definition and use of aliases. A using alias directive defines an alias for a type. Suchaliases can be useful in situation in which name collisions occur between two class libraries, or when a smallnumber of types from a much larger namespace are being used. The exampleusing MessageSource = CSharp.Introduction.HelloMessage;shows a using alias directive that defines MessageSource as an alias for the HelloMessage class.The code we have written can be compiled into a class library containing the class HelloMessage and anapplication containing the class HelloApp. The details of this compilation step might differ based on thecompiler or tool being used. A command-line compiler might enable compilation of a class library and anapplication that uses that library with the following command-line invocations:csc /target:library HelloLibrary.cscsc /reference:HelloLibrary.dll HelloApp.cswhich produce a class library named HelloLibrary.dll and an application named HelloApp.exe.8.13 VersioningVersioning is the process of evolving a component over time in a compatible manner. A new version of acomponent is source compatible with a previous version if code that depends on the previous version can,when recompiled, work with the new version. In contrast, a new version of a component is binarycompatible if an application that depended on the old version can, without recompilation, work with the newversion.Most languages do not support binary compatibility at all, and many do little to facilitate sourcecompatibility. In fact, some languages contain flaws that make it impossible, in general, to evolve a classover time without breaking at least some client code.As an example, consider the situation of a base class author who ships a class named Base. In the firstversion, Base contains no method F. A component named Derived derives from Base, and introducesan F. This Derived class, along with the class Base on which it depends, is released to customers, whodeploy to numerous clients and servers.// Author Anamespace A{public class Base // version 1{}}46

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

Saved successfully!

Ooh no, something went wrong!