- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Gets or sets the value in HybridDictionary with specified key in C#
To get or set the value in HybridDictionary with specified key, the code is as follows −
Example
using System; using System.Collections.Specialized; public class Demo { public static void Main() { HybridDictionary myDict = new HybridDictionary(); myDict.Add("1", "Tablet"); myDict.Add("2", "Desktop"); myDict.Add("3", "Speakers"); myDict.Add("4", "Laptop"); myDict.Add("5", "Notebook"); myDict.Add("6", "Ultrabook"); myDict.Add("7", "HDD"); myDict.Add("8", "SDD"); Console.WriteLine("Value at key 5 = "+myDict["5"]); } }
Output
This will produce the following output −
Value at key 5 = Notebook
Example
Let us see another example −
using System; using System.Collections.Specialized; public class Demo { public static void Main() { HybridDictionary myDict = new HybridDictionary(); myDict.Add("1", "Tablet"); myDict.Add("2", "Desktop"); myDict.Add("3", "Speakers"); myDict.Add("4", "Laptop"); myDict.Add("5", "Notebook"); myDict.Add("6", "Ultrabook"); myDict.Add("7", "HDD"); myDict.Add("8", "SDD"); Console.WriteLine("Value at key 5 = "+myDict["5"]); myDict["5"] = "Smart Watches"; Console.WriteLine("Value at key 5 [UPDATED] = "+myDict["5"]); } }
Output
This will produce the following output −
Value at key 5 = Notebook Value at key 5 [UPDATED] = Smart Watches
Example
Let us see another 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); Console.WriteLine("Queue..."); foreach(Object ob in queue) { Console.WriteLine(ob); } Console.WriteLine("Count of elements = "+queue.Count); Console.WriteLine("Synchronize access..."); lock(queue.SyncRoot) { foreach(Object ob in queue) { Console.WriteLine(ob); } } } }
Output
This will produce the following output −
Queue... 100 200 300 400 500 Count of elements = 5 Synchronize access... 100 200 300 400 500
Advertisements