Reputation: 665
I have optional parameters generated by CodeDom. For example:
class Square
{
public Square([Optional()] int side) { }
}
I have a call statement:
Square sq = new Square();
While I'm editing, my Error List window shows: 'Square' does not contain a constructor that takes 0 arguments'
But it compiles and runs successfully. How can I get rid of the error in 'Error List' window? Thanks!
Upvotes: 3
Views: 678
Reputation: 755041
What you're seeing is the difference between IDE live semantic error checking and the actual compiler running. The live semantic checking uses the C# compiler but doesn't have 100% parity with it and it can produce false positives in corner cases of the language.
To get rid of this disable live semantic checking
Another way to fix this is to use the actual C# supported syntax for optional values
public Square(int side = 0) { }
Upvotes: 5