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

middle

What are the uses of using in C#

entry

What is the difference between continue and break statements in C#?

senior

Explain the difference between Select and Where

Bình luận

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

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