TimeSpan.Add() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

1K+ Views

The TimeSpan.Add() method in C# returns a new TimeSpan object whose value is the sum of the specified TimeSpan object and the current instance. This method is useful for adding time intervals together, such as combining durations or calculating elapsed time periods. Syntax Following is the syntax for the TimeSpan.Add() method − public TimeSpan Add(TimeSpan span); Parameters span − A TimeSpan object representing the time interval to add to the current TimeSpan instance. Return Value Returns a new TimeSpan object that represents the sum of the current TimeSpan and the specified ... Read More

Get the number of elements contained in the Stack in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

296 Views

The Count property in C# provides an efficient way to get the number of elements contained in a Stack. This property returns an integer value representing the current number of items stored in the stack. Syntax Following is the syntax for using the Count property − Stack stack = new Stack(); int count = stack.Count; Return Value The Count property returns an int value representing the number of elements in the stack. For an empty stack, it returns 0. Stack Count Property ... Read More

Insert a new entry in OrderedDictionary with specified key and value in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

175 Views

The OrderedDictionary class in C# provides the Insert method to add a new entry at a specific position while maintaining the order of existing elements. This method allows you to specify both the index position and the key-value pair to insert. Syntax Following is the syntax for inserting an entry at a specific position in an OrderedDictionary − orderedDictionary.Insert(index, key, value); Parameters index − The zero-based index at which to insert the key-value pair. key − The key of the entry to insert. value − The value ... Read More

Uri.IsWellFormedOriginalString() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

129 Views

The Uri.IsWellFormedOriginalString() method in C# determines whether the original string used to construct a Uri object was well-formed and doesn't require additional escaping. This method returns true if the URI string is properly formatted according to RFC standards, and false otherwise. This method is particularly useful when validating URI strings before processing them or when you need to ensure that a URI doesn't contain characters that require percent-encoding. Syntax Following is the syntax for the IsWellFormedOriginalString() method − public bool IsWellFormedOriginalString(); Return Value The method returns a bool value − ... Read More

TimeSpan.Compare() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

2K+ Views

The TimeSpan.Compare() method in C# is a static method used to compare two TimeSpan values and returns an integer that indicates their relative relationship. This method is useful for sorting operations and determining the order of time intervals. Syntax Following is the syntax for the TimeSpan.Compare() method − public static int Compare(TimeSpan span1, TimeSpan span2); Parameters span1 − The first TimeSpan value to compare. span2 − The second TimeSpan value to compare. Return Value The method returns an integer with the following meaning − Return ... Read More

Get the number of elements in the SortedSet in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

181 Views

The Count property in C# returns the number of elements currently stored in a SortedSet. This property provides an efficient way to determine the size of the collection without having to iterate through all elements. Syntax Following is the syntax for getting the count of elements in a SortedSet − int elementCount = sortedSet.Count; Return Value The Count property returns an int value representing the total number of elements in the SortedSet. For an empty SortedSet, it returns 0. Using Count Property with String SortedSet The following example demonstrates how to ... Read More

Number of elements in HashSet in C#?

AmitDiwan
Updated on 17-Mar-2026 07:04:36

281 Views

To get the number of elements in a HashSet in C#, use the Count property. The Count property returns an integer representing the total number of unique elements stored in the HashSet. Syntax Following is the syntax for getting the count of elements in a HashSet − HashSet hashSet = new HashSet(); int count = hashSet.Count; Using Count Property with Integer HashSet The following example demonstrates how to get the number of elements in HashSets containing integers − using System; using System.Collections.Generic; public class Demo { public ... Read More

How to check Minlength and Maxlength validation of a property in C# using Fluent Validation?

Nizamuddin Siddiqui
Updated on 17-Mar-2026 07:04:36

3K+ Views

FluentValidation is a popular .NET validation library that provides an easy way to validate model properties. The MinLength and MaxLength validators ensure that string properties meet specific length requirements, making them essential for input validation scenarios. Syntax Following is the syntax for using MaximumLength validator − RuleFor(x => x.PropertyName).MaximumLength(maxValue); Following is the syntax for using MinimumLength validator − RuleFor(x => x.PropertyName).MinimumLength(minValue); MaxLength Validator The MaximumLength validator ensures that the length of a string property does not exceed the specified maximum value. This validator is only valid on string properties. ... Read More

UInt64 Struct in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

485 Views

The UInt64 struct in C# represents a 64-bit unsigned integer with values ranging from 0 to 18, 446, 744, 073, 709, 551, 615. This struct provides various methods for comparison, equality checks, and other operations on unsigned 64-bit integers. UInt64 Value Range 0 18, 446, 744, 073, 709, 551, 615 64-bit Unsigned Integer 2^64 - 1 possible values UInt64.CompareTo() Method The UInt64.CompareTo() method compares the current instance to a specified object or UInt64 value and returns an indication of their ... Read More

Insert at the specified index in StringCollection in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:36

209 Views

The StringCollection class in C# provides the Insert() method to add elements at specific positions within the collection. This method shifts existing elements to the right to make room for the new element at the specified index. Syntax Following is the syntax for the Insert() method − stringCollection.Insert(index, value); Parameters index − The zero-based index at which to insert the element. value − The string value to insert into the collection. Using Insert() Method Example using System; using System.Collections.Specialized; public class Demo { ... Read More

Advertisements