c# - What is the difference between a class having private constructor and a sealed class having private constructor? -


is there difference between , b?

class has private constructor:

class {     private a()     { } } 

class b sealed , has private constructor:

sealed class b {     private b()     { } } 

yes a can inherited nested class, while b cannot inherited @ all. legal:

public class {   private a() { }    public class derived : { } } 

note code create new a.derived() or inherit a.derived (its constructor public), no other classes outside source text of a can inherit directly a.

a typical use class enum-like values can have custom behavior:

public abstract class {   private a() { }    public abstract void dosomething();    private class oneimpl : {      public override void dosomething() { console.writeline("one"); }   }    private class twoimpl : {      public override void dosomething() { console.writeline("two"); }   }    public static readonly 1 = new oneimpl();   public static readonly 2 = new twoimpl(); } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -