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 use the sleep method in C#?
The Thread.Sleep() method in C# is used to pause the execution of the current thread for a specified period of time. This is commonly used to introduce delays in program execution or to simulate time-consuming operations. Syntax The Thread.Sleep() method has two overloads − Thread.Sleep(int millisecondsTimeout); Thread.Sleep(TimeSpan timeout); Parameters millisecondsTimeout − The number of milliseconds for which the thread is suspended. Use Timeout.Infinite (-1) to suspend the thread indefinitely. timeout − A TimeSpan that sets the amount of time for which the thread is suspended. Using Thread.Sleep() with Milliseconds ...
Read MoreHow to check if a string is a valid keyword in C#?
To check if a string is a valid keyword in C#, you can use the IsValidIdentifier method from the CodeDomProvider class. This method determines whether a given string is a valid identifier or a reserved keyword in C#. The IsValidIdentifier method returns true if the string is a valid identifier (like variable names, method names), and false if it's a reserved keyword (like for, if, class, etc.). Syntax Following is the syntax for using IsValidIdentifier method − CodeDomProvider provider = CodeDomProvider.CreateProvider("C#"); bool isIdentifier = provider.IsValidIdentifier(stringToCheck); Using IsValidIdentifier to Check Keywords Here's how ...
Read MoreThe nameof keyword in C#
The nameof operator in C# returns the string literal name of a variable, type, or member. It provides a compile-time constant string that represents the name of the code element, making it useful for logging, exception messages, and property change notifications without hardcoding strings. Syntax Following is the syntax for using the nameof operator − string name = nameof(element); Where element can be a variable, property, method, class, or namespace. Using nameof with Variables The nameof operator returns the variable name as a string, which is resolved at compile time − ...
Read MoreC# Program to add a node before the given node in a Linked List
A LinkedList in C# is a doubly-linked list that allows efficient insertion and deletion of nodes at any position. The AddBefore() method inserts a new node immediately before a specified existing node in the linked list. Syntax Following is the syntax for the AddBefore() method − public LinkedListNode AddBefore(LinkedListNode node, T value) public LinkedListNode AddBefore(LinkedListNode node, LinkedListNode newNode) Parameters node − The existing LinkedListNode before which to insert the new node. value − The value to add to the LinkedList. newNode − The new LinkedListNode to add ...
Read MoreUri.EscapeDataString(String) Method in C#
The Uri.EscapeDataString() method in C# converts a string to its escaped representation by encoding characters that are not safe for use in URI data strings. This method is essential when you need to include user data or special characters in URL components like query parameters. Syntax Following is the syntax − public static string EscapeDataString(string stringToEscape); Parameters stringToEscape: A string that contains the data to be escaped. If the string is null, the method returns null. Return Value Returns a string that contains the escaped representation of stringToEscape. How It ...
Read MoreHow to use RightShift Operators in C#?
The right shift operator (>>) in C# moves the bits of the left operand to the right by the number of positions specified by the right operand. This operation effectively divides the number by powers of 2. Syntax Following is the syntax for the right shift operator − result = operand >> numberOfPositions; Where operand is the value whose bits will be shifted, and numberOfPositions specifies how many positions to shift right. How Right Shift Works The right shift operator moves each bit to the right by the specified number of positions. ...
Read MoreC# program to find K'th smallest element in a 2D array
Finding the K'th smallest element in a 2D array requires flattening the array and sorting it to locate the element at the K'th position. This is a common programming problem that demonstrates array manipulation and sorting techniques. Approach The approach involves three main steps − Flatten the 2D array into a 1D array Sort the flattened array in ascending order Access the element at index k-1 (since arrays are zero-indexed) Finding K'th Smallest Element 2D Array ...
Read MoreEnum.GetName in C#
The Enum.GetName method in C# returns the string name of a constant in a specified enumeration that has the specified value. This method is useful when you need to convert an enum value back to its string representation for display purposes or logging. Syntax Following is the syntax for the Enum.GetName method − public static string GetName(Type enumType, object value) Parameters enumType − The enumeration type whose constant's string name you want to retrieve. value − The value of a particular enumerated constant in terms of its underlying type. ...
Read MoreC# Program to find the average of a sequence of numeric values
Use the LINQ Average() method to find the average of a sequence of numeric values. LINQ provides multiple approaches to calculate averages from collections like arrays, lists, and other enumerable sequences. Syntax Following is the syntax for using the Average() method − // For IEnumerable collection.Average() // For IQueryable Queryable.Average(collection.AsQueryable()) Return Value The Average() method returns a double value representing the arithmetic mean of the sequence. For integer sequences, the result is automatically converted to double to preserve decimal precision. Using Average() with List Collections The simplest approach is to ...
Read MoreUri.FromHex() Method in C#
The Uri.FromHex() method in C# converts a single hexadecimal digit character to its corresponding decimal integer value. This static method is part of the Uri class and is commonly used when working with URL encoding and decoding operations. Syntax Following is the syntax − public static int FromHex(char digit); Parameters digit − A hexadecimal digit character (0-9, a-f, A-F) to convert to its decimal equivalent. Return Value Returns an int value representing the decimal equivalent of the hexadecimal digit. The method throws an ArgumentException if the character ...
Read More