C# Programming - Properties - Discussion

Discussion Forum : Properties - General Questions (Q.No. 4)
4.
If a class Student has an indexer, then which of the following is the correct way to declare this indexer to make the C#.NET code snippet given below work successfully?
Student s = new Student(); 
s[1, 2] = 35;
class Student
{ 
    int[ ] a = new int[5, 5]; 
    public property WriteOnly int this[int i, int j]
    { 
        set
        { 
            a[i, j] = value;
        } 
    }
}
class Student
{ 
    int[ , ] a = new int[5, 5]; 
    public int property WriteOnly
    { 
        set
        { 
            a[i, j] = value;
        } 
    } 
}
class Student
{ 
    int[ , ] a = new int[5, 5];
    public int this[int i, int j] 
    {
        set
        { 
            a[i, j] = value;
        } 
    } 
}
class Student
{ 
    int[ , ] a = new int[5, 5];
    int i, j; 
    public int this
    { 
        set
        { 
            a[i, j] = value;
        } 
    } 
}
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
4 comments Page 1 of 1.

Bhumi said:   7 years ago
Yes, I also agree to @Swash question.

Ahmed said:   8 years ago
Why is it required?

Swash said:   8 years ago
Why this keyword is required?

Vlad said:   9 years ago
No A - We have to declare 2 dimensional array correctly.
No B - There is no this keyword in the property.
No D - No numbers in the property.

Post your comments here:

Your comments will be displayed after verification.