---
title: "What’s the difference between const and readonly?"  
description: "What’s the difference between const and readonly?"  
author: "Sumit Kesarwani"  
published: 2013-06-15  
updated: 2020-09-16  
canonical: https://www.mindstick.com/interview/1771/what-s-the-difference-between-const-and-readonly  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# What’s the difference between const and readonly?

You can initialize readonly variables to some runtime values. Let’s say your program uses current date and time as one of the values that won’t change. This way you declare

public readonly string DateT = new DateTime().ToString().

## Answers

### Answer by Durgesh Tripathi

Const:\
1. Const can only be initialized at the time of declaration of the field.\
2. Const values will evaluate at compile time only.\
3. Const value can’t be changed these will be same at all the time. \
4. This type of fields are required when one of the field values remains constant throughout the system.\
Read-only:\
1. The value will be initialized either declaration time or the constructor of the class allowing you to pass the value at run time.\
2. Read only values will evaluate at runtime only.

public class Const_VS_Readonly\
{\
public const int CONST_VALUE = 2;\
public readonly int RO_VALUE;\
public Const_VS_Readonly()\
{\
RO_VALUE = 3;\
}\
}

### Answer by Sumit Kesarwani

You can initialize readonly variables to some runtime values. Let’s say your program uses current date and time as one of the values that won’t change. This way you declare

public readonly string DateT = new DateTime().ToString().


---

Original Source: https://www.mindstick.com/interview/1771/what-s-the-difference-between-const-and-readonly

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
