---
title: "What is Difference between Constant and ReadOnly Property?"  
description: "What is Difference between Constant and ReadOnly Property?"  
author: "Hemant Patel"  
published: 2017-03-02  
updated: 2020-09-16  
canonical: https://www.mindstick.com/interview/23219/what-is-difference-between-constant-and-readonly-property  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# What is Difference between Constant and ReadOnly Property?

The **difference** is that the value of a static readonly field is set at run time, so it can have a different value for different executions of the program. However, the value of a constant field is set to a compile time constant. Read-only variables will be initialized only from the Static constructor of the class.

**Initialization** of readonly field was not compulsory but in constant it’s compulsory.

Readonly field accessed by object reference and constant accessed by class name.

The value of readonly property can be change, but constant value will be fixed.

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace Learn{     public class Constant_Vs_Readonly    {        public const int CONSTANT_INPUT = 2;        public readonly int ReadOnly_Input = 10;        public Constant_Vs_Readonly()        {             ReadOnly_Input = 4;        }        static void Main(string[] args)        {        Constant_Vs_Readonly obj = new Constant_Vs_Readonly();        Console.WriteLine(obj.ReadOnly_Input+ "" + Constant_Vs_Readonly.CONSTANT_INPUT);        Console.ReadLine();        }    }}
```

## Answers

### Answer by Hemant Patel

The **difference** is that the value of a static readonly field is set at run time, so it can have a different value for different executions of the program. However, the value of a constant field is set to a compile time constant. Read-only variables will be initialized only from the Static constructor of the class.

**Initialization** of readonly field was not compulsory but in constant it’s compulsory.

Readonly field accessed by object reference and constant accessed by class name.

The value of readonly property can be change, but constant value will be fixed.

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace Learn{     public class Constant_Vs_Readonly    {        public const int CONSTANT_INPUT = 2;        public readonly int ReadOnly_Input = 10;        public Constant_Vs_Readonly()        {             ReadOnly_Input = 4;        }        static void Main(string[] args)        {        Constant_Vs_Readonly obj = new Constant_Vs_Readonly();        Console.WriteLine(obj.ReadOnly_Input+ "" + Constant_Vs_Readonly.CONSTANT_INPUT);        Console.ReadLine();        }    }}
```


---

Original Source: https://www.mindstick.com/interview/23219/what-is-difference-between-constant-and-readonly-property

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
