Simple C# for Coding Flashcards

1
Q

What is a Hashset? How do you use it?

A

A generic list but for fast access, unordered, and it avoids duplicates
Functions: Add, Remove, Contains

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a Dictionary? How do you use it?

A

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>();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a Tuple? How do you use it?

A

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);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a List? How do you use it?

A

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>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a Queue in c#?

A

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");
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a Stack in c#?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly