Found 2587 Articles for Csharp

How to Delete Item from Hashtable Collection in C#?

Shilpa Nadkarni
Updated on 14-Dec-2022 14:01:31

496 Views

The Hashtable in C# is a collection of key−value pairs that are organized based on the hash code of the key. The items in the hashtable are accessed using a key. The Hashtable class of C# is the class that implements the hashtable. Using this class, we can create a new hashtable object with the help of the constructors provided. The Hashtable class also provides various methods using which we can perform various operations on the hashtable. These operations include adding items, checking for the existence of specified keys, counting the number of items, removing an item from the hashtable, ... Read More

How to Create a HashTable Collection in C#?

Shilpa Nadkarni
Updated on 14-Dec-2022 11:49:16

230 Views

The HashTable is a non−generic collection in C#. It stores key-value pairs and is similar to a generic “Dictionary” collection. HashTable is defined in System. Collections. namespace. HashTable computes the hash code of each key and stores it in a different bucket internally. The hash code is then matched to the hash code of the specified key when the values are accessed. Thus the lookups are optimized by HashTable. In this tutorial, we will see how we can create a HashTable collection in C#. Hashtable Features Before we jump to creating a HashTable, let us see some of ... Read More

How to Check if a Key Exists in the Hashtable in C#?

Shilpa Nadkarni
Updated on 14-Dec-2022 11:47:21

2K+ Views

The Hashtable class in C# represents a collection of key-value pairs. These key-value pairs are organized based on the hash code of the key that is calculated using the hash code function. The key in the hashtable accesses the items. So given a key, we can access the corresponding value for that key in the hashtable. The keys in the hashtable are unique and non-null. The values however can be null or duplicated. We have been discussing hashtable topics in our earlier tutorials. We continue the trend in this article as well. In this article, we will discuss how to ... Read More

How to Add Items to Hashtable Collection in C#

Shilpa Nadkarni
Updated on 14-Dec-2022 11:40:06

791 Views

We have already discussed the basics of hashtables. A hashtable collection in C# is used to store key−value pairs wherein each of these key-value pairs is organized based on the hash code of the key. This hash code is calculated using a hash code function. Internally, the hashtable uses buckets to store data. A bucket is nothing but a virtual group of elements within the hashtable. A hash code is associated with each bucket. Programmatically, a hashtable is similar to a dictionary object but unlike in dictionary object, a hashtable can store objects of different data types. Performance−wise, hashtables exhibit ... Read More

How to find the number of times array is rotated in the sorted array by recursion using C#?

Nizamuddin Siddiqui
Updated on 27-Aug-2021 13:47:21

316 Views

Find index of mid element (minimum element) Apply Binary Search on the subarray based on following conditions −If number lies between start element and element at mid1 position.Then find number in array start to mid-1 using binary searchElse if number lies between mid and last element, then find number in array mid to last element using binary search.Example Live Demousing System; using System.Collections.Generic; using System.Text; using System.Linq; namespace ConsoleApplication{    public class Arrays{       public int FindNumberRotated(int[] array, int start, int end, int value){          if (start > end){             return ... Read More

How to find the minimum number of steps needed by knight to reach the destination using C#?

Nizamuddin Siddiqui
Updated on 27-Aug-2021 13:40:34

343 Views

We have to make the knight cover all the cells of the board and it can move to a cell only once.There can be two ways of finishing the knight move - the first in which the knight is one knight's move away from the cell from where it began, so it can go to the position from where it started and form a loop, this is called closed tour, the second in which the knight finishes anywhere else, this is called open tour. A move is valid if it is inside the chessboard and if the cell is not ... Read More

How to find all the different combinations of opening and closing brackets from the given number k using C#?

Nizamuddin Siddiqui
Updated on 27-Aug-2021 13:40:18

391 Views

Create a backtrack function that updates the current string if open brackets are less than n or close bracket are less than open bracket. When the length of current string becomes equal to 2*n, add it to the combination result array. It could be simply tracked by keeping the number of { } placed . We can start an opening bracket if we still have one left to place. And we can start a closing bracket if it would not exceed the number of opening brackets.Example Live Demousing System; using System.Collections.Generic; using System.Text; using System.Linq; namespace ConsoleApplication{    public class BackTracking{ ... Read More

How to find the unique combination of sum from the given number C#?

Nizamuddin Siddiqui
Updated on 27-Aug-2021 13:32:02

386 Views

Create an output list to store the valid sequences, create a current list that will store the current sequence found in the path of the recursion tree. A backtrack function that will go into the recursion until the target is achieved, otherwise, it should backtrack to the previous phase as target becomes less than 0. At any point in time, if target becomes 0 then add the candidate array to the result as the values in the candidate array must be sum up to the given target.If those are not the cases then, one by one add the elements in ... Read More

How to find the unique combination k sum that corresponds to k sum using C#?

Nizamuddin Siddiqui
Updated on 27-Aug-2021 13:27:29

288 Views

Create an output list to store the valid sequences, create a current list that will store the current sequence found in the path of the recursion tree. A backtrack function that will go into the recursion until the target is achieved, otherwise, it should backtrack to the previous phase as target becomes less than 0. At any point in time, if target becomes 0 then add the candidate array to the result as the values in the candidate array must be sum up to the given target.If those are not the cases then, one by one add the elements in ... Read More

How to find the distinct subsets from a given array by backtracking using C#?

Nizamuddin Siddiqui
Updated on 27-Aug-2021 13:24:48

360 Views

Distinct subsets problem gives us the different combination from the given array.When the target is 2 then from the array, we take all the combination that corresponds to number 2, When the target is three then from the array, we take all the combination that corresponds to count 3. In the below example the array is [1, 2, 3] and the target is 2. So, we take all the combinations the corresponds to number 2 “1, 2 “, “2, 3”, ”1, 3””.Example Live Demousing System; using System.Collections.Generic; using System.Text; using System.Linq; namespace ConsoleApplication{    public class BackTracking{       public ... Read More

Advertisements