adplus-dvertising

Welcome to the Indexers and Exception Handling MCQs Page

Dive deep into the fascinating world of Indexers and Exception Handling with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Indexers and Exception Handling, a crucial aspect of C# programming. In this section, you will encounter a diverse range of MCQs that cover various aspects of Indexers and Exception Handling, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within C# programming.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Indexers and Exception Handling. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of C# programming.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Indexers and Exception Handling. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Indexers and Exception Handling MCQs | Page 1 of 13

Discuss
Answer: (b).A property can be either read only or write only.
Q2.
A Student class has a property called rollNo and stu is a reference to a Student object and we want the statement stu.RollNo = 28 to fail. Which of the following options will ensure this functionality?
Discuss
Answer: (d).Declare rollNo property with only get accessor.
Discuss
Answer: (c).class Student
{
int[ , ] a = new int[5, 5];
public int this[int i, int j]
{
set
{
a[i, j] = value;
}
}
}
Q4.
Which of the following statements are correct?

1. The signature of an indexer consists of the number and types of its formal parameters.
2. Indexers are similar to properties except that their accessors take parameters.
3. Accessors of interface indexers use modifiers.
4. The type of an indexer and the type of its parameters must be at least as accessible as the indexer itself.
5. An interface accessor contains a body.
Discuss
Answer: (b).1, 2, 4
Q5.
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;
Discuss
Answer: (b).2, 4, 5
Discuss
Answer: (d).class Sample
{
int len;
public int Length
{
set
{
len = value;
}
}
}
Q7.
If a Student class has an indexed property which is used to store or retrieve values to/from an array of 5 integers, then which of the following are the correct ways to use this indexed property?

1.
Student[3] = 34;

2.
Student s = new Student();
s[3] = 34;

3.
Student s = new Student();
Console.WriteLine(s[3]);

4.
Console.WriteLine(Student[3]);

5.
Student.this s = new Student.this();
s[3] = 34;
Discuss
Answer: (b).2, 3
Q8.
If Sample class has a Length property with set accessor then which of the following statements will work correctly?
Discuss
Answer: (d).Sample m = new Sample();
m.Length = 10;
Q9.
If Sample class has a Length property with get accessor then which of the following statements will work correctly?
Discuss
Answer: (c).Sample m = new Sample();
int l;
l = m.Length;
Q10.
An Account class has a property called accountNo and acc is a reference to a bank object and we want the C#.NET code snippet given below to work. Which of the following options will ensure this functionality?

acc.accountNo = 10; 
Console.WriteLine(acc.accountNo);
Discuss
Answer: (a).Declare accountNo property with both get and set accessors.
Page 1 of 13

Suggested Topics

Are you eager to expand your knowledge beyond C# programming? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!