Hi guys! is it possible to call parameterized constructor from derived class no-parameters constructor?
To be clear - I want to override the most simple exception constructor (withpout parametrs) by other one - with string-parameter for class -

public class SetEception : ApplicationException

thanks in advance)

Recommended Answers

All 3 Replies

as I understand - it can be realized so -

public SetEception(): base(String.Format("{0}","1234")) ;
        {
            
        }

You can create as many constructors as you like. One can have no parameters, 2nd can have one, 3rd constructor can have 3 parameters and so on.
When you create a new instance of a class you then pass as many parameters as you have in those constructors. It will be called that constructor with the same number of parameters.

Can you clarify your statements from post 1 a bit better? I didnt understand it.

commented: +++++++ +1

Mitja, I couldn't understand how to express constructor without variables , which calls parent constructor with variables because of specific syntax of base()-expression where there isn't a type of variable -- for example .

public SetEception(): base(String.Format("{0}","1234")) ;

is there any more way to tell the С# that the variable has definite type? (for examle - string - as it's in my case)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.