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
Programming Articles
Page 104 of 2547
C# 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 MoreHashSet in C#
A HashSet in C# is a high-performance collection that stores unique elements and automatically eliminates duplicates. It provides fast lookups, insertions, and deletions with O(1) average time complexity, making it ideal for scenarios where you need to maintain a collection of distinct values. HashSet is part of the System.Collections.Generic namespace and implements the ISet interface, providing mathematical set operations like union, intersection, and difference. Syntax Following is the syntax for declaring and initializing a HashSet − HashSet hashSetName = new HashSet(); You can also initialize it with an existing collection − ...
Read MoreStreams and Byte Streams in C#
A file is a collection of data stored in a disk with a specific name and a directory path. When a file is opened for reading or writing, it becomes a stream. Streams in C# provide a unified interface for reading and writing data, whether it's from files, memory, or network connections. The type of streams includes − Byte Streams − They handle raw binary data and include Stream, FileStream, MemoryStream, and BufferedStream. Character Streams − They handle text data and include TextReader, TextWriter, StreamReader, StreamWriter, and other text-based streams. Byte ...
Read MoreC# program to convert floating to binary
Converting a floating-point number to binary representation in C# involves separating the number into its integer and fractional parts, then converting each part separately using different algorithms. The integer part is converted using repeated division by 2, while the fractional part is converted using repeated multiplication by 2. Algorithm The conversion process follows these steps − Separate the floating-point number into integer and fractional parts Convert the integer part by repeatedly dividing by 2 and collecting remainders Convert the fractional part by repeatedly multiplying by 2 and collecting integer parts Combine both parts with a ...
Read More