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
C# program to check if a value is in an array
Use the Array.Exists method to check if a value is in an array or not. This method returns a boolean value indicating whether the specified element exists in the array. Syntax Following is the syntax for Array.Exists method − public static bool Exists(T[] array, Predicate match) Parameters array − The one-dimensional array to search. match − A predicate that defines the conditions of the element to search for. Return Value Returns true if the array contains an element that matches the conditions defined by the ...
Read MoreC# Program to remove a node at the beginning of a Linked List
To remove a node at the beginning of a LinkedList in C#, use the RemoveFirst() method. This method removes the first node from the LinkedList and automatically adjusts the internal structure. Syntax Following is the syntax for the RemoveFirst() method − linkedList.RemoveFirst(); This method removes the first node and does not return any value. If the LinkedList is empty, it throws an InvalidOperationException. How It Works When you call RemoveFirst(), the LinkedList performs the following operations − RemoveFirst() Operation ...
Read MoreValidate IP Address in C#
An IP Address is an Internet Protocol address that is a series of numbers assigned to each device on a computer network. In C#, the IPAddress class in the System.Net namespace provides methods to work with and validate IP addresses. There are several approaches to validate IP addresses in C#, including using the built-in IPAddress.TryParse() method and regular expressions for custom validation. Syntax Following is the syntax for using IPAddress.TryParse() method − bool IPAddress.TryParse(string ipString, out IPAddress address) Parameters ipString − A string that contains an IP address in dotted-decimal notation ...
Read MoreChar.IsWhiteSpace() Method in C#
The Char.IsWhiteSpace() method in C# is used to determine whether a specified Unicode character is classified as white space. This includes spaces, tabs, line feeds, carriage returns, and other Unicode whitespace characters. Syntax Following is the syntax for the Char.IsWhiteSpace() method − public static bool IsWhiteSpace(char ch); Parameters ch − The Unicode character to evaluate. Return Value Returns true if the character is a whitespace character; otherwise, false. Char.IsWhiteSpace() Method Input char ch ...
Read MorePriority Queues with C#
A priority queue is a data structure that stores elements with associated priority values. It is an extension of a regular queue where elements are served based on their priority rather than their insertion order. When you remove an item from a priority queue, the element with the highest priority is removed first. If two elements have the same priority, they are typically served in the order they were inserted. Syntax Following is the basic syntax for creating a priority queue class − public class MyPriorityQueue where T : IComparable { private ...
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 MoreImplicit conversion from Int32 to Decimal in C#
The int type represents a 32-bit signed integer (Int32) in C#. C# allows implicit conversion from int to decimal because this conversion is always safe and does not result in data loss. The decimal type has a much larger range and precision than int. Syntax The syntax for implicit conversion from Int32 to decimal is straightforward − int intValue = 123; decimal decimalValue = intValue; // implicit conversion No explicit casting is required because the conversion is safe and automatic. How Implicit Conversion Works When you assign an int value to ...
Read MoreHow to create user defined exceptions in C#?
In C#, you can create user-defined exceptions by deriving from the Exception class or one of its derived classes. User-defined exceptions allow you to create specific error types that are meaningful to your application domain, making error handling more precise and informative. Syntax Following is the basic syntax for creating a user-defined exception class − public class CustomExceptionName : Exception { public CustomExceptionName() : base() { } public CustomExceptionName(string message) : base(message) { } public CustomExceptionName(string message, Exception innerException) : ...
Read MoreDateTime.IsLeapYear() Method in C#
The DateTime.IsLeapYear() method in C# is used to determine whether a specified year is a leap year. This static method returns true if the year is a leap year, and false otherwise. A leap year occurs every 4 years, with exceptions for century years that are not divisible by 400. Syntax Following is the syntax − public static bool IsLeapYear(int year); Parameters year − An integer representing the year to be checked. The year must be between 1 and 9999. Return Value Returns a bool value − ...
Read MoreWhat are generic collections in C#?
Generic collections in C# are type-safe collections that allow you to specify the type of elements at compile time. They provide better performance, type safety, and IntelliSense support compared to non-generic collections like ArrayList and Hashtable. The most commonly used generic collections include List, Dictionary, SortedList, Queue, and Stack. These are part of the System.Collections.Generic namespace. Syntax Following is the syntax for declaring generic collections − List listName = new List(); Dictionary dictName = new Dictionary(); SortedList sortedListName = new SortedList(); Where T, TKey, and TValue are type parameters that specify the actual ...
Read More