Pergunta de entrevista da empresa CG-VAK Software

What is the difference between constant and readonly in C#?

Resposta da entrevista

Sigiloso

24 de ago. de 2023

Const is nothing but "constant," a variable whose value is constant but at compile time. Therefore, it's mandatory to assign a value to it. By default, a const is static, and we cannot change the value of a const variable throughout the entire program. Readonly is the keyword whose value we can change during runtime or assign it at run time but only through the non-static constructor.