- 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
volatile keyword in C#
To reduce concurrency issues in C#, use the volatile keyword. Let us seen an example.
The following is how you use a volatile keyword for public variable −
class Program { public volatile int a; public void Program(int _a) { i = _i; } }
Let us see another example: We have two static variables. Set them in a new method −
_out = "Welcome!"; _new = true;
We declared them as static before using volatile −
static string _out; static volatile bool new;
Now you need to run the method on a thread −
new Thread(new ThreadStart(volatileFunc)).Start();
Read the value of the volatile variable −
if (_new) { Console.WriteLine(_out); }
- Related Articles
- What is volatile keyword in C++?
- volatile Keyword in Java
- What does the volatile keyword mean in C++?
- Can we make Array volatile using volatile keyword in Java?
- “volatile” qualifier in C
- Volatile Storage vs Non-Volatile Storage
- Difference between Volatile Memory and Non-Volatile Memory
- Why do we use a volatile qualifier in C++?
- What is the difference between Volatile and Non-Volatile substances?
- Static Keyword in C++
- “extern” keyword in C
- “register” keyword in C
- Restrict keyword in C
- override Keyword in C++
- Final keyword in C#

Advertisements