---
title: "What is the difference between const and read-only in C#?"  
description: "What is the difference between const and read-only in C#?"  
author: "Steilla Mitchel"  
published: 2023-07-12  
updated: 2023-07-13  
canonical: https://www.mindstick.com/forum/159049/what-is-the-difference-between-const-and-read-only-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# What is the difference between const and read-only in C#?

What is the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between [const](https://www.mindstick.com/forum/105419/what-is-the-difference-between-read-only-and-const-keyword) and read-only in C#?

## Replies

### Reply by Aryan Kumar

The `const` and `readonly` keywords in C# are both used to declare constants. However, there are some key differences between the two keywords.

- `const` **constants are compile-time constants, while** `readonly` **constants are runtime constants.** This means that the value of a `const` constant is known at compile time, while the value of a `readonly` constant can be changed at runtime.
- `const` **constants must be initialized when they are declared, while** `readonly` **constants can be initialized later.** This means that you cannot declare a `const` constant without initializing it, while you can declare a `readonly` constant and initialize it later.
- `const` **constants are implicitly static, while** `readonly` **constants can be static or non-static.** This means that a `const` constant is always a static member of a class, while a `readonly` constant can be a static member or an instance member of a class.

In general, you should use `const` constants when the value of the constant is known at compile time and you do not need to be able to change the value at runtime. You should use `readonly` constants when the value of the constant can be changed at runtime, or when you need to be able to declare a constant that is not a static member of a class.

Here is a table that summarizes the key differences between `const` and `readonly`:

| Feature | `const` | `readonly` |
| --- | --- | --- |
| Compile-time constant | Yes | No |
| Initialization | Must be initialized when declared | Can be initialized later |
| Static | Implicitly static | Can be static or non-static |
| When to use | When the value of the constant is known at compile time and you do not need to be able to change the value at runtime | When the value of the constant can be changed at runtime, or when you need to be able to declare a constant that is not a static member of a class |


---

Original Source: https://www.mindstick.com/forum/159049/what-is-the-difference-between-const-and-read-only-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
