C# Programming - Properties - Discussion

Discussion Forum : Properties - General Questions (Q.No. 6)
6.
If Sample class has a Length property with get and set accessors then which of the following statements will work correctly?
  1. Sample.Length = 20;
  2. Sample m = new Sample(); 
    m.Length = 10;
  3. Console.WriteLine(Sample.Length);
  4. Sample m = new Sample(); 
    int len;
    len = m.Length;
  5. Sample m = new Sample(); 
    m.Length = m.Length + 20;
1, 3
2, 4, 5
4 only
3, 5
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
2 comments Page 1 of 1.

Santhosh said:   10 years ago
Can any one please explain how its working?

Deepak Holmes said:   9 years ago
In choice(2), they are setting a value of length property to 10.

In choice(4), first a variable len of int datatype is declared and then the len variable is assigned with the value in Length property(using get accessor).

In choice(5), they used both setter and getter modifiers.

Post your comments here:

Your comments will be displayed after verification.