13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>C#</strong> LANGUAGE SPECIFICATIONclass B: A{public override void F() {base.F();}}// Error, base.F is abstracta compile-time error is reported for the base.F() invocation because it references an abstract method. endexample]An abstract method declaration is permitted to override a virtual method. This allows an abstract class to force reimplementationof the method in derived classes, and makes the original implementation of the methodunavailable. [Example: In the exampleusing System;class A{public virtual void F() {Console.WriteLine("A.F");}}abstract class B: A{public abstract override void F();}class C: B{public override void F() {Console.WriteLine("C.F");}}class A declares a virtual method, class B overrides this method with an abstract method, and class C overridesthat abstract method to provide its own implementation. end example]17.5.7 External methodsWhen a method declaration includes an extern modifier, the method is said to be an external method. Externalmethods are implemented externally, typically using a language other than <strong>C#</strong>. Because an external methoddeclaration provides no actual implementation, the method-body of an external method simply consists of asemicolon.The mechanism by which linkage to an external method is achieved, is implementation-defined.[Example: The following example demonstrates the use of the extern modifier in combination with aDllImport attribute that specifies the name of the external library in which the method is implemented:end example]using System.Text;using System.Security.Permissions;using System.Runtime.InteropServices;class Path{[DllImport("kernel32", SetLastError=true)]static extern bool CreateDirectory(string name, SecurityAttribute sa);[DllImport("kernel32", SetLastError=true)]static extern bool RemoveDirectory(string name);[DllImport("kernel32", SetLastError=true)]static extern int GetCurrentDirectory(int bufSize, StringBuilder buf);[DllImport("kernel32", SetLastError=true)]static extern bool SetCurrentDirectory(string name);}238

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

Saved successfully!

Ooh no, something went wrong!