Register to Better Coder! It's free.
Enjoy the premium features and succeed at every job interview.
How can you assign a value to a property in C#?
Experience Level: Junior
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# Junior
What is the 'new' keyword used for in C#?C# Junior
How can you recognize a property in C#?C# Junior
What is a property in C#?C# Junior
What is a class instance in C#?C# Junior