Discussion Forum

  1. Home
  2. »
  3. Languages
  4. »
  5. If a class Student has...
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: C .
 class Student
{ 
    int[ , ] a = new int[5, 5];
    public int this[int i, int j] 
    {
        set
        { 
            a[i, j] = value;
        } 
    } 
}
0Shares
0 0

If you think the posted answer is wrong or Confused About the Answer? Ask for Details Here

Know Explanation? Add it Here
we’ll review your comment and contact you soon….

Leave a Reply

Your email address will not be published. Required fields are marked *

0Shares
0
Scroll to Top