Error in Creating Structs
-
Hey All, i am new to programming and they asked me to create a struct for calculating Area with the length and width. I have coded but it shows error and please help me to correct the error and i will paste my code here.
Struct Area { Public int length; Public int width; Public int area; Public Area(int _length, int _width) { this.length=_length; this.width=_width; this.area=(_length* _width); } Public int GetArea() { return area; } static void main(int[] args) { Area area=new Area(); Console.Writeline(area.GetArea()); } }
Chitra -
Hey All, i am new to programming and they asked me to create a struct for calculating Area with the length and width. I have coded but it shows error and please help me to correct the error and i will paste my code here.
Struct Area { Public int length; Public int width; Public int area; Public Area(int _length, int _width) { this.length=_length; this.width=_width; this.area=(_length* _width); } Public int GetArea() { return area; } static void main(int[] args) { Area area=new Area(); Console.Writeline(area.GetArea()); } }
Chitrachitra4sat wrote:
Area area=new Area();
You have no public constructor with this signature. Your only constructor takes two arguments, (int _length and int _width). Either add a new constructor with no parameters, or call the existing constuctor with the appropriate arguments;
Area area=new Area(0, 0);
Rhys
ELYSIUM, n. An imaginary delightful country which the ancients foolishly believed to be inhabited by the spirits of the good. This ridiculous and mischievous fable was swept off the face of the earth by the early Christians -- may their souls be happy in Heaven!
Ambrose Bierce (1842 - 1914)
Behind every argument is someone's ignorance.
Louis D. Brandeis (1856 - 1941)