Simple C# for Coding Flashcards
What is a Hashset? How do you use it?
A generic list but for fast access, unordered, and it avoids duplicates
Functions: Add, Remove, Contains
What is a Dictionary? How do you use it?
A generic collection for key/value pairs
Keys should be unique
Dynamic, no need to specify size while initializing
Key can not be null, value can be
using System.Collections.Generic;
Dictionary<int, string> myDictionary = new Dictionary<int, string>();
What is a Tuple? How do you use it?
A lightweight data structure that you can use to group loosely related data elements. Also very handy to return multiple values from a method.
using System.Collections.Generic;
// Tuple with one element
Tuple<string>My_Tuple1 = new Tuple<string>("GeeksforGeeks");</string></string>
// Tuple with three elements
Tuple<string, string, int>My_Tuple2 = new Tuple<string, string, int>(“Romil”, “Python”, 29);
OR
// Using Create Method
var My_Tuple1 = Tuple.Create(“GeeksforGeeks”);
// Creating 4-tuple
// Using Create Method
var My_Tuple2 = Tuple.Create(12, 30, 40, 50);
What is a List? How do you use it?
It is a generic dynamic collection which is used to store elements
using System.Collections.Generic;
List<int> my_list = new List<int>();</int></int>
What is a Queue in c#?
A first in first out (FIFO) collection of objects.
Enqueue, Dequeue are the methods for access
You are allowed to store duplicates
Accepts null values as valid
Dynamic size
using System.Collections; // Using Queue class Queue my_queue = new Queue(); // Adding elements in Queue my_queue.Enqueue("GFG"); my_queue.Enqueue(1); my_queue.Enqueue(100); my_queue.Enqueue(null); my_queue.Enqueue(2.4); my_queue.Enqueue("Geeks123");
What is a Stack in c#?