What are the benefits to using a partial class as opposed to an abstract one?

后端 未结 8 1642
花落未央
花落未央 2021-01-18 01:19

I have been reading Programming Microsoft® Visual C#® 2008: The Language to get a better understanding of C# and what can be done with it. I came across partial classes whic

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-18 01:53

    Partial class are now used heavily in ASP.Net to allow two source files the mark-up based example.aspx and the code based example.aspx.cs so that methods and variable defined in each are visible to each. in the example.aspx

    
    

    in the example.aspx.cs

    private object GetProperty(){ // called from aspx
        return DateTime.Now;
    }
    
    private void DoStuff(){
        ExampleControl c = exampleCntr; //exampleCntr is defined in aspx.
    }
    

    The bi-directional nature of this cannot be recreated with abstract classes.

提交回复
热议问题