0
0
C Sharp (C#)programming~10 mins

Multi-parameter indexers in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a multi-parameter indexer that returns an integer.

C Sharp (C#)
public int this[int [1], int col] { get { return data[row, col]; } }
Drag options to blanks, or click blank then click option'
Arow
Bindex
Ci
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name that does not match the usage inside the getter.
Using a single parameter instead of two.
2fill in blank
medium

Complete the code to set a value using the multi-parameter indexer.

C Sharp (C#)
public int this[int row, int [1]] { set { data[row, col] = value; } }
Drag options to blanks, or click blank then click option'
Acol
Bindex
Cpos
Dcolumn
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name that does not match the setter's code.
Using a single parameter instead of two.
3fill in blank
hard

Fix the error in the indexer declaration by completing the parameter list.

C Sharp (C#)
public string this[[1]] { get { return matrix[row, col]; } }
Drag options to blanks, or click blank then click option'
Aint index
Bint row, int col
Cstring key
Dint x, int y, int z
Attempts:
3 left
💡 Hint
Common Mistakes
Using only one parameter for a 2D indexer.
Using incorrect parameter types.
4fill in blank
hard

Fill both blanks to complete the multi-parameter indexer that sets a value in a 2D array.

C Sharp (C#)
public double this[[1], [2]] { set { grid[row, col] = value; } }
Drag options to blanks, or click blank then click option'
Aint row
Bint index
Cint col
Ddouble val
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-integer parameter types.
Using parameter names that do not match the setter.
5fill in blank
hard

Fill all three blanks to complete the multi-parameter indexer with get and set accessors for a 3D array.

C Sharp (C#)
public char this[[1], [2], [3]] { get { return cube[x, y, z]; } set { cube[x, y, z] = value; } }
Drag options to blanks, or click blank then click option'
Aint x
Bint y
Cint z
Dchar c
Attempts:
3 left
💡 Hint
Common Mistakes
Using fewer than three parameters.
Using incorrect parameter types or names.