How can you assign a value to a property in C#?
Experience Level: Junior
Tags: C#
Answer
In order to assign a value to a property of an object that is stored in a variable, just type a name of that variable, dot character, name of the property, equals sign, a value that you want to assign and a semicolon in the end.
In the example below, the property VolumeLevel will be set to value 10. Note that the property VolumeLevel belongs to object that is stored in the variable myRadio. The object was created based on the class Radio. We are saying the object is of type Radio.
Related C# job interview questions
What is a variable?
C# JuniorWhat is the 'new' keyword used for in C#?
C# JuniorHow can you recognize a property in C#?
C# JuniorWhat is a property in C#?
C# JuniorWhat is a class instance in C#?
C# Junior