How can you recognize a property in C#?

Experience Level: Junior
Tags: C#

Answer

Whenever you see a dot character in the code, have a look at the right hand side from it. If you see a string that is not ended by opening rounded brackets, you very likely found a property.

In the example below, you can see that the value 10 is set to the the property VolumeLevel of the object that is stored in a variable myRadio. On the next line the value is retrieved from this property and it is stored to the newly declared variable volumeLevel.

Example
public class Program 
{
  public static void Main() {
    var myRadio = new Radio();
	myRadio.VolumeLevel = 10;
	
	var volumeLevel = myRadio.VolumeLevel;
  }
}

Comments

No Comments Yet.
Be the first to tell us what you think.
C# for beginners
C# for beginners

Are you learning C# ? Try our test we designed to help you progress faster.

Test yourself