
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Queue.IsSynchronized Property in C#
The Queue.IsSynchronized() method in C# is used to GET a value indicating whether access to the Queue is synchronized (thread safe).
Syntax
The syntax is as follows −
public virtual bool IsSynchronized { get; }
Example
Let us now see an example −
using System; using System.Collections; public class Demo { public static void Main() { Queue queue = new Queue(); queue.Enqueue(100); queue.Enqueue(200); queue.Enqueue(300); queue.Enqueue(400); queue.Enqueue(500); queue.Enqueue(600); queue.Enqueue(700); queue.Enqueue(800); queue.Enqueue(900); queue.Enqueue(1000); Console.WriteLine("Queue..."); IEnumerator demoEnum = queue.GetEnumerator(); while (demoEnum.MoveNext()) { Console.WriteLine(demoEnum.Current); } Console.WriteLine("Is Queue synchronized? = "+queue.IsSynchronized); } }
Output
This will produce the following output −
Queue... 100 200 300 400 500 600 700 800 900 1000 Is Queue synchronized? = False
Example
Let us now see another example −
using System; using System.Collections; public class Demo { public static void Main() { Queue queue = new Queue(); queue.Enqueue("AB"); queue.Enqueue("BC"); queue.Enqueue("CD"); queue.Enqueue("DE"); queue.Enqueue("EF"); queue.Enqueue("FG"); queue.Enqueue("GH"); queue.Enqueue("HI"); Console.WriteLine("Queue..."); IEnumerator demoEnum = queue.GetEnumerator(); while (demoEnum.MoveNext()) { Console.WriteLine(demoEnum.Current); } Console.WriteLine("Is Queue synchronized? = "+queue.IsSynchronized); Queue queue2 = Queue.Synchronized(queue); Console.WriteLine("Is Queue synchronized now? = "+queue2.IsSynchronized); } }
Output
This will produce the following output −
Queue... AB BC CD DE EF FG GH HI Is Queue synchronized? = False Is Queue synchronized now? = True
Advertisements