Question
a.
class Student
{
int[] scores = new int[5] {3, 2, 4,1, 5};
public int this[ int index ]
{
set
{
if (index < 5)
scores[index] = value;
else
Console.WriteLine("Invalid Index");
}
}
}
b.
class Student
{
int[] scores = new int[5] {3, 2, 4, 1, 5};
public int this[ int index ]
{
get
{
if (index < 5)
return scores[ index ];
else
{
Console.WriteLine("Invalid Index"); return 0;
}
}
set
{
if (index < 5)
scores[ index ] = value;
else
Console.WriteLine("Invalid Index");
}
}
}
c.
class Student
{
int[] scores = new int[5] {3, 2, 4, 1, 5};
public int this[ int index ]
{
get
{
if (index < 5)
return scores[ index ];
else
{
Console.WriteLine("Invalid Index");
return 0;
}
}
}
}
d.
class Student
{
int[] scores = new int[5] {3, 2, 4, 1, 5};
public int this[ int index ]
{
get
{
if (index < 5)
scores[ index ] = value;
else
{
Console.WriteLine("Invalid Index");
}
}
set
{
if (index < 5)
return scores[ index ];
else
{
Console.WriteLine("Invalid Index");
return 0;
}
}
}
}
Posted under C# programming
{
int[] scores = new int[5] {3, 2, 4, 1, 5};
public int this[ int index ]
{
get
{
if (index < 5)
return scores[ index ];
else
{
Console.WriteLine("Invalid Index"); return 0;
}
}
set
{
if (index < 5)
scores[ index ] = value;
else
Console.WriteLine("Invalid Index");
}
}
}
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. Suppose a Student class has an indexed property. This property is used to set or retrieve values to/from an array of 5 integers called scores[]. We want the property to report...
Similar Questions
Discover Related MCQs
Q. Which of the following statements is correct about properties used in C#.NET?
View solution
Q. Which of the following is the correct way to implement a read only property Length in a Sample class?
View solution
Q. An Employee class has a property called age and emp is reference to a Employee object and we want the statement Console.WriteLine(emp.age) to fail. Which of the following options will ensure this functionality?
View solution
Q. Which of the following is NOT a .NET Exception class?
View solution
Q. Which of the following statements is correct about an Exception?
View solution
Q. In C#.NET if we do not catch the exception thrown at runtime then which of the following will catch it?
View solution
Q. Which of the following is the Object Oriented way of handling run-time errors?
View solution
Q. Exceptions can be thrown even from a constructor, whereas error codes cannot be returned from a constructor.
View solution
Q. All code inside finally block is guaranteed to execute irrespective of whether an exception occurs in the protected block or not.
View solution
Q. Which of the following is NOT an Exception?
View solution
Q. It is compulsory for all classes whose objects can be thrown with throw statement to be derived from System.Exception class.
View solution
Q. Which of the following statements is true about an enum used in C#.NET?
View solution
Q. An enum that is declared inside a class, struct, namespace or interface is treated as public.
View solution
Q. An enum can be declared inside a class, struct, namespace or interface.
View solution
Q. Which of the following CANNOT be used as an underlying datatype for an enum in C#.NET?
View solution
Q. Which of the following statements is correct about an enum used in C#.NET?
View solution
Q. Choose the correct statement among the followings?
View solution
Q. Choose the keyword which declares the indexer?
View solution
Q. Choose the operator/operators which is/are not used to access the [] operator in indexers?
View solution
Q. Choose the correct statement among the following?
View solution
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!
Operating System
Dive deep into the core of computers with our Operating System MCQs. Learn about...
Java Programming
Level up your coding skills with our Java Programming MCQs. From object-oriented...