Resolve error 'there is no argument given that corresponds to required formal parameter'?

Fixing your bug:

The error occurs due to the lack of a parameterless constructor (or your lack of using the base() method in your constructor (just like user3185569 had said)

Fixing your code:

It clearly seems you are lacking some basics in .NET so I've decided to give a re-writing to your code with the following things in mind:

a. Conventions

There are some rules about common conventions that should apply to your code.

Members usually begin with either m or _ and then the memberName (camel casing).

Properties are usually written regularly as PropertyName and same applies to methods.

Parameters and variables are simply camel cased like parameterName

b. Access Modifiers

I don't know the use of your Oval and circle but I assume you'd want to access them outside of Oval and Circle.

I think it would be the best to reference you to here to read some more about the topic: https://msdn.microsoft.com/en-us/library/ms173121.aspx

I've re-written your code to include all those tips (and also fix your issue)

public class Oval:Shape
{       
    //Constructor
    public Oval(double majorAxis, double minorAxis)
    {
        MajorAxis=majorAxis;
        MinorAxis=minorAxis;
    } 
    
    protected double MajorAxis{ get; set; }     
    protected double MinorAxis{ get; set; }     
}    

public class Circle:Oval
{       
    //Constructor
    public Circle(double radius): base(radius,radius)
    {
        radius = Circle_Radius;  
    }
    
    public double Radius
    {
        get
        {
            return MajorAxis;
        }
        set
        {
            MajorAxis = value;
            MinorAxis = value;
        }       
    }
}

Since Circle inherits from Oval, when you create a Circle the default constructor for Oval is called in your case. Since that constructor accepts 2 parameters, you need to explicitly call the constructor and provide them:

class Circle : Oval
{
    private double radius;
    public Circle(double Circle_Radius) : base(0, 0) // change to whatever values
    {
      radius = Circle_Radius;  
    }
}

So A Circle is an Oval, so it has major_axis and minor_axis values. You just didn't provide them as they are required values to create an Oval.

Of course you can add a default public constructor for Oval with no parameters, but that makes you create a Oval with no major_axis and minor_axis and both seems required by the only constructor in the current status of your code. So, you need to rethink how to design your classes.

Tags:

C#

Oop