Why the default C # classes (written by Microsoft) do not obey the same C # rules as the classes written by the encoder

My question is, if I do not have a default constructor in Class A(which is a base class and has other 2 or 3 constructors different from the standard one), how could I run a constructor different from the standard one Class Bthat I got from Class A.

But I saw that this does not apply to the default C # classes, I worked with value providers in asp.net mvc and came across a class called FormValueProviderthat was derived from its base class NameValueCollectionValueProvider.

FormValueProviderhas only one constructor that has a parameter of type ControllerContext. And the base class NameValueCollectionValueProviderhas two constructors, one with two type parameters NameValueCollectionand, CultureInforespectively, and the other with three parameters, two of which are a type NameValueCollection, and the third is a typeCultureInfo.

How can I instantiate a class with its only parameterized constructor when it does not have a default constructor. Why does this rule exist for a programmer who writes his own code, not applicable to standard C # classes written by Microsoft. FormValueProvider NameValueCollectionValueProvider

+3
source share
3 answers

Because they call them with thisand, baserespectively.

, FormvalueProvider FormvalueProvider:

public FormValueProvider(ControllerContext controllerContext)
           : this(controllerContext,
             new UnvalidatedRequestValuesWrapper(controllerContext.HttpContext.Request.Unvalidated()))

NameValueCollectionValueProvider:

internal FormValueProvider(ControllerContext controllerContext, IUnvalidatedRequestValues unvalidatedValues) 
             : base(controllerContext.HttpContext.Request.Form, 
                    unvalidatedValues.Form, 
                    CultureInfo.CurrentCulture)

, internal.., , . , , , , .

base : http://msdn.microsoft.com/en-us/library/hfw7t1ce.aspx

+4

# , , . , , base.

, :

class Employee {
    public Employee(string title) {}
}

class Manager: Employee {
    public Manager() : base("Manager") {}
}

Manager Employee , Manager Employee.

+3

, internal. :

public class BaseClass 
{
    internal BaseClass() {}

    protected BaseClass(String myString) 
    {
        /* do some stuff */
    }
}

public class ChildClass 
{
    public ChildClass()
        : base() 
    {
        /* do some stuff */
    }
}

internal, (, ). .NET, , , .

+1

All Articles