Question discussion

Which statement about const and readonly fields in C# is correct?

1718Medium DSSSB TGT Computer Science 0 replies 1 views
0

Which statement about const and readonly fields in C# is correct?

  • AA const value is fixed at compile time, whereas a readonly field can be assigned at run time inside a constructor.
  • BBoth const and readonly fields are always assigned at run time.
  • CA readonly field cannot be assigned anywhere in the program.
  • DA const field can be assigned inside the constructor.
Correct answer: A

Explanation

const is a compile-time constant, while readonly fields are initialised at declaration or in a constructor and can differ between objects.

Discussion 0

Nobody has replied yet. Start the discussion!