Câu hỏi phỏng vấn C#
Câu hỏi

What is difference between constant and readonly ?

Câu trả lời

Here is the difference between constant and readonly in C#:

Constant

  • A constant is a variable whose value cannot be changed after it has been assigned.
  • The value of a constant must be known at compile-time.
  • Constants are declared using the const keyword.
  • Constants can be accessed without creating an instance of the class.
  • Constants are stored in the assembly's metadata.
  • Constants can be of any primitive data type (int, double, char, etc.) or string.

Example:

csharp Copy
public const double PI = 3.14159;

Readonly

  • A readonly field is a variable whose value can be assigned only once, either at the declaration or in the constructor.
  • The value of a readonly field can be calculated at runtime.
  • Readonly fields are declared using the `readonl...
middle

middle

Gợi ý câu hỏi phỏng vấn

expert

Why Abstract class can not be sealed or static?

middle

What is the difference between Virtual method and Abstract method?

junior

How is Exception Handling implemented in C#?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào