Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# ambiguity error when properties are used

I've recently started learning C#. I just learned about properties and decided to make a simple program in order to understand them more. this is the code I wrote:

  class Dog
{
    private int weight;
    private string colour;
    public string colour { get; set; }
    public Dog(int theWeight, string theColour)
    {
        weight = theWeight;
        colour = theColour;
    }
}

And i get an ambiguity error. As far a I understand, this shouldn't happen.

like image 409
Adrien Avatar asked Aug 03 '10 07:08

Adrien


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C in C language?

What is C? C is a general-purpose programming languagegeneral-purpose programming languageIn computer software, a general-purpose programming language (GPL) is a programming language designed to be used for building software in a wide variety of application domains, across a multitude of hardware configurations and operating systems.https://en.wikipedia.org › wiki › General-purpose_programmi...General-purpose programming language - Wikipedia created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What == means in C?

The equal-to operator ( == ) returns true if both operands have the same value; otherwise, it returns false .


2 Answers

You have a field and a property with the same name colour. That is why the compiler produces an error.

like image 174
DixonD Avatar answered Sep 22 '22 01:09

DixonD


ambiguity error is that you named field and property tha same name "colour". change the property definition f.e.

public string Colour
{
 get { return colour;}
 set { colour = value;}
}
like image 30
Arseny Avatar answered Sep 22 '22 01:09

Arseny