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

in C#, when should we use abstract classes instead of interfaces with extension methods?

senior

What interface should your data structure implement to make the Where method work?

expert

Could you explain the difference between destructor , dispose and finalize method?

Bình luận

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

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