
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What is the difference between keywords const and readonly in C#?
Const
Constant fields are the fields that cannot be modified. At the time of declaration, you need to assign a value to it.
const int a = 5;
Readonly
A Read-only field is initialized at the time of declaration or you can also set it within the constructor.
Let us see an example in which the read-only field is initialized inside the constructor −
Example
class Calculate { readonly int z; public Demo( ) { z = 20; } }
- Related Articles
- Explain the difference between const and readonly keywords in C#
- Difference between readonly and const keyword in C#
- What is the difference between const int*, const int * const, and int const *?
- Difference between const int*, const int * const, and int const * in C/C++?
- What is the difference between #define and const Keyword in C++?
- Difference between const int*, const int * const, and int const * in C
- What is difference between int and const int& in C/C++?
- What is the difference between VAR and DYNAMIC keywords in C#?
- Const vs Static vs Readonly in C#
- What is the difference between public, static and void keywords in C#?
- What is the difference between "const" and "val" in Kotlin?
- Difference between const char* p, char * const p, and const char * const p in C
- Difference between #define and const in C
- What is the difference between keywords and reserved words in Java?
- What is the difference between super and this, keywords in Java?

Advertisements