AmbitionBox

Discover Best Places to work in India

C# Programming

C# Programming Questions and Answers

Showing 1 - 9 of 9 questions

1

Choose the correct statement among the following?

a

A property can be a static member whereas an indexer is always an instance member

b

A get accessor of a property corresponds to a method with no parameters whereas get accessor of an indexer corresponds to a method with the same formal parameters lists as the indexer

c

It is an error for indexer to declare a local variable with the same name as indexer parameters

d

All of the mentioned

correct answer d

Answer: Option (D)

2

Choose the keyword which declares the indexer?

a

base

b

this

c

super

d

extract

correct answer b

The indexer is declared using the name this.

3

Choose the operator/operators which is/are used to access the [] operator in indexers?

a

get

b

set

c

access

d

All of the mentioned

correct answer a,b

The indexer is implemented through the get and set accessors for the [] operator as:
public double this[int idx] {
get
{
if()
{
}
else
{
return([idx]);
}

 

}
set
{
array[idx];

}
}

4

Choose the correct statement among the followings?

a

Indexers are location indicators

b

Indexers are used to access class objects

c

Indexer is a form of property and works in the same way as a property

d

None of the mentioned

correct answer a,b,c

Answer: Options (A), (B) and (C)

By definition

5

For a class student consisting of indexer,which among the following declaration of indexers runs the code successfully ?
student a = new student();
a[1,2] = 20;

a
class student
   {int[,] p =newint[6, 6];public property WriteOnly intthis[int i, int j]{set{
               a[i, j]=value;}}}
b
class student
   {int[,] a =newint[6, 6];publicintthis[int i, int j]{set{
               a[i, j]=value;}}}
c
class student
   {int[,] a =newint[6, 6];publicint property WriteOnly
       {set{
               a[i, j]=value;}}}
d
 None of the mentioned
correct answer b

Answer: Option (B)

6

Choose the correct option among the following indexers which correctly allows to index in same way as an array?

a

A class

b

An interface

c

A function

d

A property

correct answer a,b

Answer: Option (A) and (B)

7

Which among the following are the advantages of using indexers?

a

To use collection of items at a large scale we make use of indexers as they utilize objects of class that represent the collection as an array

b

Indexers are also convenient as they can also make use of different types of indexers like int, string etc

c

None of the mentioned

d

All of the mentioned

correct answer a,b

Indexers provides a view at large scale to visualize a collection of items as an array.It is really easy to use the object of the class that represents a collection as if it is an array.Hence, indexed properties allow us to represent such a view. Indexers can also use different types of indexes like int , string etc. Use int as an index where sequential access to a collection is desired.When symbolic access is needed,use string as an index.

8

Choose the correct alternative that utilizes the indexed property such that a group named class has indexed property which stores or retrieves value to/from an array of 5 numbers?

a

group[3] = 34;

b

group g = new group();
g[3] = 34;

c

Console.WriteLine(group[3]);

d

group g = new group();
Console.WriteLine(g[3]);

correct answer b,d

Answer: Option (B) and (D)

9

Choose the correct statement about properties describing the indexers?

a

No need to use the name of the property while using an indexed property

b

An indexer property should accept at least one argument

c

Indexers can be overloaded

d

All of the mentioned

correct answer d

Answer: Option (D)

Select a company to compare with

vs

Similar Companies