0

I have generated this simplified version of my problem:

public class Variable { public Variable(string s, int i) { } public Variable(string str) : base(str, 0) // error here { } } 

Clearly I have a constructor that take 2 arguments. But the error is saying that I don't.

I am confused.

I am using .NET Standard 2.0

Please ask for any additional clarification.

1
  • 6
    : this(str, 0) instead of : base(str, 0) Commented Oct 2, 2018 at 20:44

2 Answers 2

3

base class (object in your case) doesn't have such a constructor

 object(string s, int i) 

But your current class this does have the required constructor:

public class Variable { public Variable(string s, int i) { } public Variable(string str) : this(str, 0) // current class constructor call { } } 
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for saving my day.. I knew only about base() to overload contructors in c#.. Is it (use of this) only in .net-standard or everywhere in c# ?
@Muzib: this as a current class constructor can be used everywhere in c#
3
: base(str, 0) 

is calling the Object constructor which doesn't have one for 2 parameters.

use this instead

: this(str, 0) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.