Compiler Error - Seeking help

L

lumien

When using the following code, I get the error "The type
"ConsoleApplication1.robot" already contains a definition for
'color"". I also get the error for "height".

If anyone could point me to the answer to this issue or documentation
describing what I am doing incorrectly I would appreciate it.

Thanks,
Jason

****Code****

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class robot
{
/* Defining robot attributes */

private string color;
private double height;

/* sets robot color */

public string color
{
get {return this.color; }
set {this.color = value; }
}

/* sets robot height */

public double height
{
get {return this.height; }
set { this.height = value; }
}

/* Create Object
<param color => color of robot </param>
<param height => height of robot </param>
*/

public robot(String color, Double height)
{
this.color = color;
this.height = height;
}
/* calculates weight based on height */

public double weight()
{
return 5 * this.height;
}

/*overloads ToString */

public string ToString()
{
return string.Format("{0,-20},{1,-10},{2,-10F1}",
this.color, this.height, this.weight());
}
}
}
 
F

Fred Mellender

the accessor, "color/get/set", and the member datum "color" have the same
name. Rename the member variable to something like "theColor", and have
accessor "color/get" return it. Similarly for your other problems....
 
L

lumien

the accessor, "color/get/set", and the member datum "color" have the same
name. Rename the member variable to something like "theColor", and have
accessor "color/get" return it. Similarly for your other problems....


















- Show quoted text -


Thx, I will try that.
 
J

Jon Skeet [C# MVP]

Fred Mellender said:
the accessor, "color/get/set", and the member datum "color" have the same
name. Rename the member variable to something like "theColor", and have
accessor "color/get" return it. Similarly for your other problems....

Preferrably, keep the name of the field as color, but name the property
Color, to fit in with .NET naming conventions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top