Programming Articles

Page 801 of 2547

Validate IP Address in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 2K+ Views

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 More

Char.IsWhiteSpace() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 578 Views

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 More

Priority Queues with C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 343 Views

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 More

C# program to merge two sorted arrays into one

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 2K+ Views

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 More

Implicit conversion from Int32 to Decimal in C#

George John
George John
Updated on 17-Mar-2026 2K+ Views

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 More

How to create user defined exceptions in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 383 Views

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 More

DateTime.IsLeapYear() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 3K+ Views

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 More

What are generic collections in C#?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 842 Views

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

BitConverter.ToBoolean() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 213 Views

The BitConverter.ToBoolean() method in C# returns a Boolean value converted from the byte at a specified position in a byte array. This method reads a single byte and returns true if the byte is non-zero, or false if the byte is zero. Syntax Following is the syntax − public static bool ToBoolean(byte[] value, int startIndex); Parameters value − An array of bytes. startIndex − The starting position within the byte array. Return Value Returns true if the byte at startIndex in the array is non-zero; otherwise, false. ...

Read More

Int64.CompareTo Method in C# with Examples

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 280 Views

The Int64.CompareTo() method in C# is used to compare the current long instance with a specified object or Int64 value and returns an integer indicating their relative values. This method is essential for sorting operations and value comparisons. Syntax The Int64.CompareTo() method has two overloads − public int CompareTo(long value); public int CompareTo(object value); Parameters value − In the first overload, it's a long integer to compare. In the second overload, it's an object to compare, which must be null or an instance of Int64. Return Value The method ...

Read More
Showing 8001–8010 of 25,466 articles
« Prev 1 799 800 801 802 803 2547 Next »
Advertisements