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
Server Side Programming Articles
Page 798 of 2109
SortedMap Interface in C#
In C#, there is no direct equivalent to Java's SortedMap interface. However, C# provides the SortedList and SortedDictionary collections which offer similar functionality for maintaining key-value pairs in sorted order. The SortedList collection in C# uses both a key and an index to access items. It combines the features of an array and a hash table, maintaining items in sorted order based on the key values. You can access items either by index (like an ArrayList) or by key (like a Hashtable). Syntax Following is the syntax for creating a SortedList − SortedList sortedList = ...
Read MoreDate format validation using C# Regex
Date format validation in C# ensures that user input matches the expected date format before processing. The most reliable approach is using the DateTime.TryParseExact method, which validates both the format and the actual date values. For more complex pattern matching, Regular Expressions (Regex) can also be used. Syntax Following is the syntax for DateTime.TryParseExact method − bool DateTime.TryParseExact(string s, string format, IFormatProvider provider, DateTimeStyles style, out DateTime result) Following is the syntax for Regex date validation − Regex regex = new Regex(@"pattern"); bool isMatch = regex.IsMatch(dateString); ...
Read MoreC# program to list the difference between two lists
To find the difference between two lists in C#, you can use the Except() method from LINQ. This method returns elements from the first list that are not present in the second list, effectively giving you the set difference. Syntax Following is the syntax for using Except() method to find list difference − IEnumerable result = list1.Except(list2); Where list1 is the source list and list2 contains elements to exclude from the result. Using Except() Method The Except() method performs a set difference operation, returning elements that exist in the first collection but ...
Read MoreC# program to merge two sorted arrays into one
Merging two sorted arrays in C# involves combining the elements of both arrays into a single array while maintaining the sorted order. This is a fundamental operation used in algorithms like merge sort and when combining datasets. Approaches to Merge Sorted Arrays There are two main approaches to merge sorted arrays − Simple Concatenation: Append all elements from both arrays and then sort the result. Merge Algorithm: Compare elements from both arrays and merge them in sorted order without additional sorting. Using Simple Concatenation The simplest approach is to ...
Read MoreWhat is unmanaged code in C#?
Unmanaged code in C# refers to code that executes outside the control of the .NET Common Language Runtime (CLR). This type of code is also known as unsafe code because it bypasses many of the safety mechanisms that make C# a managed language. In C#, unmanaged code typically involves the use of pointers and direct memory manipulation, similar to languages like C and C++. To use unmanaged code, you must explicitly mark code blocks with the unsafe keyword. Key Characteristics of Unmanaged Code Applications that are not under the control of the CLR are unmanaged. ...
Read MoreFlow control in try catch finally in C#
The flow control in try-catch-finally blocks in C# follows a specific execution order depending on whether exceptions occur. Understanding this flow is crucial for proper error handling and resource management in your applications. Syntax Following is the syntax for try-catch-finally blocks − try { // Code that may throw an exception } catch (ExceptionType e) { // Exception handling code } finally { // Code that always executes } Flow Control Rules The try block executes first and contains code that might ...
Read MoreHow to convert Decimal to Binary using C#?
Converting decimal numbers to binary in C# can be accomplished using the division and modulus operators. This process involves repeatedly dividing the decimal number by 2 and collecting the remainders, which form the binary representation when reversed. The algorithm works by dividing the decimal value by 2, storing the remainder (which is always 0 or 1), and continuing until the quotient becomes 0. The binary representation is formed by reading the remainders in reverse order. Algorithm The conversion process follows these steps − Divide the decimal number by 2 Store the remainder ...
Read MoreHow to check if String is Palindrome using C#?
A palindrome is a string that reads the same forwards and backwards, such as "Level", "madam", or "racecar". In C#, there are several ways to check if a string is a palindrome. Using Array.Reverse() Method The simplest approach is to reverse the string and compare it with the original. First, convert the string to a character array − char[] ch = str.ToCharArray(); Then reverse the array using Array.Reverse() − Array.Reverse(ch); Finally, compare the reversed string with the original using case-insensitive comparison − bool res = str.Equals(rev, StringComparison.OrdinalIgnoreCase); ...
Read MoreLinkedList in C#
The LinkedList class in C# is a doubly-linked list implementation found in the System.Collections.Generic namespace. Unlike arrays or lists, a linked list allows for efficient insertion and removal of elements at any position without the need to shift other elements. Each element in a LinkedList is stored in a node that contains the data and references to both the next and previous nodes. This structure enables fast insertion and deletion operations at the cost of direct indexed access. Syntax Following is the syntax for creating a LinkedList − LinkedList linkedList = new LinkedList(); ...
Read MoreHow to find the file using C#?
Use the Directory.GetFiles and Directory.GetDirectories methods in C# to search for files in a directory structure. These methods provide powerful options to recursively search through subdirectories and apply search patterns. Syntax Following is the syntax for finding files using Directory.GetFiles − string[] files = Directory.GetFiles(path, searchPattern, SearchOption.AllDirectories); Following is the syntax for finding directories using Directory.GetDirectories − string[] directories = Directory.GetDirectories(path, searchPattern, SearchOption.AllDirectories); Parameters path − The directory path to search in searchPattern − The search string to match file/folder names (supports wildcards like * and ?) SearchOption ...
Read More