C # 2.0 partial features

xiaoxiao2021-03-06  77

Partial This is the new feature of C # 2.0 Partial keywords to combine a Class segmentation, which can be used for multiple interfaces or one inheritance

Code segment:

Namespace com.tommylib {public interface a {void a_fun1 (); void a_fun2 ();}} // New B.CS

Namespace com.tommylib {public partial class b {public b () {}} public partial class b: a // This is used to add B.CS with interface A interface {public void a_fun1 () {throw new notimplementException () Public void a_fun2 () {throw new notimplementException ();}}} // New c.csnamespace com.Tommylib {public class c {public c ()} protected void c_fun () {Console.writeline ("c_fun" } Public void c_fun1 () {console.writeline ("c_fun2");}}}} public class d {} public interface e {void e_fun ();} public partial class b: c // partial segment class b Here inherit Class c {public void b_fun () {console.writeline ("b_fun"); c_fun ();}} / * // cannot inherit multiple classes, B inherit Class C, can't inherit Classd, follow C # can't repeate Letter regulations Public Partial Class B: D {} * / P Ublic Partial Class B: E / / Can be multiple interfaces, here Class B has Interface E interface {#Region E MEMBERS PUBLIC VOID E_FUN () {throw new notimplementException ();} #ENDREGON}}

A.cs.b.cs c.cs There are two interfaces, three classes, class b, A, E two interfaces. Inherited in Class C.

C # 2.0 Partial keyword can be divided into several partial written in a class file. Follow C # not multiple inheritance but can have a number of interfaces.

The above code uses Microsoft Visual C # 2005 Express to complete the test. Frameworks 2.0.40607 Beta1

转载请注明原文地址:https://www.9cbs.com/read-51259.html

New Post(0)