Properties

Q1:
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;

A
class Student
{ 
    int[ ] a = new int[5, 5]; 
    public property WriteOnly int this[int i, int j]
    { 
        set
        { 
            a[i, j] = value;
        } 
    }
}

B
class Student
{ 
    int[ , ] a = new int[5, 5]; 
    public int property WriteOnly
    { 
        set
        { 
            a[i, j] = value;
        } 
    } 
}

C
class Student
{ 
    int[ , ] a = new int[5, 5];
    public int this[int i, int j] 
    {
        set
        { 
            a[i, j] = value;
        } 
    } 
}

D
class Student
{ 
    int[ , ] a = new int[5, 5];
    int i, j; 
    public int this
    { 
        set
        { 
            a[i, j] = value;
        } 
    } 
}

ANS:A -

class Student
{ 
    int[ ] a = new int[5, 5]; 
    public property WriteOnly int this[int i, int j]
    { 
        set
        { 
            a[i, j] = value;
        } 
    }
}

No answer description is available. Let's discuss.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.