Click here to Skip to main content
15,900,816 members
Home / Discussions / C#
   

C#

 
QuestionC# Error Pin
JacquesDP19-Feb-06 20:51
JacquesDP19-Feb-06 20:51 
AnswerRe: C# Error Pin
Stefan Troschuetz19-Feb-06 21:36
Stefan Troschuetz19-Feb-06 21:36 
GeneralRe: C# Error Pin
JacquesDP19-Feb-06 21:48
JacquesDP19-Feb-06 21:48 
Questionchange a user's group or account type in c# Pin
am2h19-Feb-06 20:26
am2h19-Feb-06 20:26 
QuestionHow to hide Windows Console Application? Pin
pubududilena19-Feb-06 20:23
pubududilena19-Feb-06 20:23 
AnswerRe: How to hide Windows Console Application? Pin
J. Dunlap19-Feb-06 20:30
J. Dunlap19-Feb-06 20:30 
QuestionFTP Client woes Pin
User 137680019-Feb-06 20:15
User 137680019-Feb-06 20:15 
QuestionUsing Multiple constructors in base and sub class Pin
miftha19-Feb-06 18:17
miftha19-Feb-06 18:17 
I have the following problem.
Say, that I have a class called Point which has x,y and the distance from (0,0).
There are two constructors, one take all three values and the other take only x ,y.

I subclass this to a circle class which has its own radius and distance from (0,0). To initialize I want to use two different constructor that use either of the base class constructors.

This causes an error in the program. Why is that, is there any solution

Check the following code and the error msg.

// Point3 class represents an x-y coordinate pair.

using System;

namespace CylinderTest
{
// Point3 class definition implicitly inherits from Object
public class Point3
{
// point coordinate
int x, y;

// default constructor
public Point3()
{
// implicit call to Object constructor occurs here
}

// constructor
public Point3( int xValue, int yValue )
{
// implicit call to Object constructor occurs here
X = xValue;
Y = yValue;
}

// property X
public int X
{
get
{
return x;
}

set
{
x = value; // no need for validation
}

} // end property X

// property Y
public int Y
{
get
{
return y;
}

set
{
y = value; // no need for validation
}

} // end property Y

// return string representation of Point3
public override string ToString()
{
return "[" + X + ", " + Y + "]";
}

} // end class Point3
}



// Circle4 class that inherits from class Point3.

using System;

namespace CylinderTest
{
// Circle4 class definition inherits from Point3
public class Circle4 : Point3
{
private double radius;

// default constructor
public Circle4()
{
// implicit call to Point constructor occurs here
}

// constructor
public Circle4( int xValue, int yValue, double radiusValue )
: base( xValue, yValue )
{
Radius = radiusValue;
}

// constructor
public Circle4( int xValue, int yValue )
: base( xValue, yValue )
{

}

// property Radius
public virtual double Radius
{
get
{
return radius;
}

set
{
if ( value >= 0 )
radius = value;
}

} // end property Radius

// calculate Circle diameter
public double Diameter()
{
return Radius * 2;
}

// calculate Circle circumference
public double Circumference()
{
return Math.PI * Diameter();
}

// calculate Circle area
public virtual double Area()
{
return Math.PI * Math.Pow( Radius, 2 );
}

// return string representation of Circle4
public override string ToString()
{
// use base reference to return Point string representation
return "Center= " + base.ToString() +
"; Radius = " + Radius;
}

} // end class Circle4
}


// Cylinder class inherits from class Circle4.

using System;

namespace CylinderTest
{
// Cylinder class definition inherits from Circle4
public class Cylinder : Circle4
{
private double height;
private double radius;

// default constructor
public Cylinder()
{
// implicit call to Circle4 constructor occurs here
}

// four-argument constructor
public Cylinder( int xValue, int yValue, double radiusValue,
double heightValue ) : base( xValue, yValue, radiusValue )
{
Height = heightValue; // set Cylinder height
}

// four-argument constructor
public Cylinder( int xValue, int yValue, double radiusValue,
double heightValue ) : base( xValue, yValue )
{
Height = heightValue; // set Cylinder height
Radius = radiusValue;
}

// property Height
public override double Radius
{
get
{
return height;
}

set
{
if ( value >= 0 ) // validate height
height = value;
}

} // end property Height

// property Height
public double Height
{
get
{
return height;
}

set
{
if ( value >= 0 ) // validate height
height = value;
}

} // end property Height

// override Circle4 method Area to calculate Cylinder area
public override double Area()
{
return 2 * base.Area() + base.Circumference() * Height;
}

// calculate Cylinder volume
public double Volume()
{
return base.Area() * Height;
}

// convert Cylinder to string
public override string ToString()
{
return base.ToString() + "; Height = " + Height;
}

} // end class Cylinder
}

lOOK FOR THE MULTIPLE CONSTRUCTORS IN CYLINDER AND CIRCLE THIS WILL NOT COMPLITE

ERROR
Class 'CylinderTest.Cylinder' already defines a member called 'Cylinder' with the same parameter types



A. Miftha Idroos
B.Sc. Engineering, AMBCS, AMIE(SL)
Hatton National Bank,
Sri Lanka

-- modified at 1:20 Monday 20th February, 2006
GeneralRe: Using Multiple constructors in base and sub class Pin
Guffa19-Feb-06 18:54
Guffa19-Feb-06 18:54 
AnswerRe: Using Multiple constructors in base and sub class Pin
J4amieC19-Feb-06 21:35
J4amieC19-Feb-06 21:35 
AnswerRe: Using Multiple constructors in base and sub class Pin
Guffa19-Feb-06 22:01
Guffa19-Feb-06 22:01 
QuestionColumn Sequence changes when binding Arraylist of Structs to Datagrid Pin
Adarsh Shah19-Feb-06 17:33
Adarsh Shah19-Feb-06 17:33 
QuestionPainting controls... Pin
Kasic Slobodan19-Feb-06 17:24
Kasic Slobodan19-Feb-06 17:24 
QuestionHelp on Word Document (2003) XML Support Pin
ted_92119-Feb-06 15:03
ted_92119-Feb-06 15:03 
AnswerRe: Help on Word Document (2003) XML Support Pin
malharone19-Feb-06 16:10
malharone19-Feb-06 16:10 
QuestionDataSets & TableAdapters Pin
monrobot1319-Feb-06 15:03
monrobot1319-Feb-06 15:03 
QuestionC# throw exception code format Pin
edel_ong19-Feb-06 14:03
edel_ong19-Feb-06 14:03 
AnswerRe: C# throw exception code format Pin
Christian Graus19-Feb-06 14:37
protectorChristian Graus19-Feb-06 14:37 
AnswerRe: C# throw exception code format Pin
Sean8919-Feb-06 14:55
Sean8919-Feb-06 14:55 
GeneralRe: C# throw exception code format Pin
Sean8920-Feb-06 1:46
Sean8920-Feb-06 1:46 
QuestionI need help Pin
loncountrygirl19-Feb-06 13:42
loncountrygirl19-Feb-06 13:42 
AnswerRe: I need help Pin
Christian Graus19-Feb-06 14:01
protectorChristian Graus19-Feb-06 14:01 
GeneralRe: I need help Pin
loncountrygirl19-Feb-06 14:45
loncountrygirl19-Feb-06 14:45 
GeneralRe: I need help Pin
loncountrygirl19-Feb-06 14:49
loncountrygirl19-Feb-06 14:49 
GeneralRe: I need help Pin
Sean8919-Feb-06 15:07
Sean8919-Feb-06 15:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.