BLoB
BLoB

Reputation: 9725

BaseController parameterised constructor

I have a BaseController as follows:

public class BaseController : Controller
{
    string ApplicationName;

    public BaseController(string applicationName)
    {
        ApplicationName = applicationName;
    }
}

The question is how can I pass a string as a parameter for the BaseController when it is inherited by the CSController, e.g.

public class CSController : BaseController{"CustomerSite"}
{
}

Upvotes: 2

Views: 51

Answers (2)

Oguz Ozgul
Oguz Ozgul

Reputation: 7187

You can call the base class constructor from your own constructor like this:

public class CSController : BaseController
{
    public CSController()
        : base("CustomerSite")
    {
    }
}

Upvotes: 1

Yacoub Massad
Yacoub Massad

Reputation: 27871

You can pass parameters to the base class constructor from the derived class constructor like this:

public class CSController : BaseController
{
    public CSController()
        :base("CustomerSite")
    {
    }
}

Upvotes: 2

Related Questions