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.
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 ...
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? 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.
The equal-to operator ( == ) returns true if both operands have the same value; otherwise, it returns false .
You have a field and a property with the same name colour
. That is why the compiler produces an error.
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;}
}
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