What is a read only object? e. g.static readonly object padlock = new object();

Questions by mkatpatal   answers by mkatpatal

Showing Answers 1 - 6 of 6 Answers

A read only member is like a constant in that it represents an unchanging value. The difference is that a readonly member can be initialized at runtime, in a constructor as well being able to be initialized as they are declared. For example

public class MyClass
{
  public readonly double PI = 3.14159;
}

Because a readonly field can be initialized either at the declaration or in a constructor, readonly fields can have different values depending on the constructor used. A readonly field can also be used for runtime constants as in the following example

public static readonly uint l1 = (uint)DateTime.Now.Ticks;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions