- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Const vs Static vs 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;
Static
If the static modifier is applied to a class then you cannot instantiate the class using the new keyword. You can use the static keyword on methods, properties, classes, constructors, etc.
static int a = 10;
Readonly
A Readonly 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 readonly field is initialized inside the constructor.
Example
class Demo { readonly int a; public Demo( ) { a = 5; } }
- Related Articles
- "static const" vs "#define" vs "enum" ?
- enum vs. const vs. #define in C/C++
- Const vs Let in JavaScript.
- Static vs. Non-Static method in C#
- Compare define() vs const in PHP
- static keyword in C++ vs Java
- Static binding vs Dynamic binding in C#
- Static vs Dynamic Binding in Java
- Difference between readonly and const keyword in C#
- Class method vs static method in Python
- Static methods vs Instance methods in Java
- C++ vs C++0x vs C++11 vs C++98
- Virtual vs Sealed vs New vs Abstract in C#
- C++ vs Java vs Python?
- Tokens vs Identifiers vs Keywords in C++

Advertisements