Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to iterate any Map in C#
C# doesn't have a built-in Map type like Java. Instead, C# uses Dictionary to achieve the same functionality. A Dictionary stores key-value pairs and provides several ways to iterate through its contents. Syntax Following is the syntax for creating a Dictionary − Dictionary dictionary = new Dictionary(); Following are the common iteration patterns − // Iterate over keys foreach (var key in dictionary.Keys) { } // Iterate over values foreach (var value in dictionary.Values) { } // Iterate over key-value pairs foreach (var kvp in dictionary) { } ...
Read MoreC# Linq Contains Method
The Contains() method in LINQ is used to check whether a sequence contains a specific element. It returns true if the element is found, otherwise false. This method works with any IEnumerable collection including arrays, lists, and queryable sequences. Syntax Following is the syntax for using Contains() with collections − bool result = collection.Contains(element); Following is the syntax for using Contains() with queryable sequences − bool result = collection.AsQueryable().Contains(element); Parameters element − The value to locate in the sequence. Return Value Returns true if the ...
Read MoreChar.ConvertToUtf32(String, Int32) Method in C#
The Char.ConvertToUtf32(String, Int32) method in C# is used to convert the value of a UTF-16 encoded character or surrogate pair at a specified position in a string into a Unicode code point. This method is particularly useful when working with Unicode characters that may be represented as surrogate pairs in UTF-16 encoding. Syntax Following is the syntax − public static int ConvertToUtf32(string s, int index); Parameters s − The string that contains a character or surrogate pair. index − The index position of the character or surrogate pair in ...
Read MoreC# Program to display name of Current Thread
To display the name of the current thread in C#, use the Name property of the Thread.CurrentThread object. This property allows you to both set and retrieve the name of the currently executing thread. Syntax Following is the syntax to get the current thread − Thread thread = Thread.CurrentThread; Following is the syntax to set and get the thread name − thread.Name = "ThreadName"; string currentName = thread.Name; Using Thread.CurrentThread Property The Thread.CurrentThread property returns a reference to the currently executing thread. You can then use the Name property ...
Read MoreMethods of the Thread Class
The Thread class in C# provides several methods to control and manage thread execution. The most commonly used methods are Start(), Sleep(), Join(), and Abort() (though Abort() is obsolete in .NET Core and later versions). Commonly Used Thread Methods Method Description Start() Starts the execution of a thread Sleep(int milliseconds) Pauses the current thread for specified time Join() Blocks calling thread until this thread terminates Interrupt() Interrupts a thread in WaitSleepJoin state Using Start() and Join() Methods The Start() method ...
Read MoreHow to iterate efficiently through an array of integers of unknown size in C#
To iterate efficiently through an array of integers of unknown size in C#, there are several approaches available. The key is to use the array's Length property or built-in iteration methods that automatically handle the array size. Syntax Following is the syntax for basic array iteration using a for loop − for (int i = 0; i < arr.Length; i++) { // access arr[i] } Following is the syntax for using foreach loop − foreach (int element in arr) { // access element directly ...
Read MoreC# Program to search for a string in an array of strings
Searching for a string in an array of strings is a common programming task. C# provides several methods to accomplish this, with the most straightforward being the LINQ Contains() method. This method returns a boolean value indicating whether the specified string exists in the array. Syntax Following is the syntax for using Contains() method to search in an array − array.Contains(searchString) You can also use it with AsQueryable() for LINQ queries − array.AsQueryable().Contains(searchString) Using LINQ Contains() Method The simplest approach is to use the LINQ Contains() method which returns ...
Read MoreInfinity or Exception in C# when divide by 0?
When dividing by zero in C#, the behavior depends on the data type being used. Integer division by zero throws a DivideByZeroException, while floating-point division by zero returns Infinity or NaN (Not a Number) without throwing an exception. Syntax Following is the basic division syntax that can result in divide-by-zero scenarios − result = dividend / divisor; Exception handling syntax for integer division − try { result = dividend / divisor; } catch (DivideByZeroException ex) { // handle exception } Integer Division ...
Read MoreHow to iterate over a C# dictionary?
A Dictionary in C# is a collection of key-value pairs that can be iterated using several different approaches. Each method provides access to keys, values, or both simultaneously. Syntax Following is the syntax for declaring and initializing a Dictionary − Dictionary dict = new Dictionary(); dict.Add(key, value); Following are the common iteration patterns − // Using KeyValuePair foreach (KeyValuePair pair in dict) { // Access pair.Key and pair.Value } // Using Keys collection foreach (TKey key in dict.Keys) { // Access key and dict[key] } ...
Read MoreC# Linq Count method
The Count method in LINQ returns the number of elements in a sequence. It is one of the most commonly used LINQ methods for determining collection size and can be used with arrays, lists, and any IEnumerable collection. Syntax Following is the syntax for the basic Count method − int count = collection.Count(); Following is the syntax for Count with a predicate condition − int count = collection.Count(predicate); Using Count() on Arrays and Collections The Count method can be applied to any collection that implements IEnumerable. Here's how to ...
Read More