I have following code where I'm getting error while compiling in C# visual Studio 2015.
class Oval:Shape
{
private double major_axis, minor_axis;
public Oval(double Major_Axis, double Minor_Axis)
{
major_axis = Major_Axis;
minor_axis = Minor_Axis;
} //Constructor
}
class Circle:Oval
{
private double radius;
public Circle(double Circle_Radius) // Getting Error on this line
{
radius = Circle_Radius;
} //constructor
}
Error CS7036 There is no argument given that corresponds to the required formal parameter (Xamarin Forms) - Microsoft Q&A.
base (C# Reference) The base keyword is used to access members of the base class from within a derived class: Call a method on the base class that has been overridden by another method. Specify which base-class constructor should be called when creating instances of the derived class.
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;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With