Programming Articles

Page 103 of 2547

Get the number of elements contained in SortedList in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 142 Views

The Count property in C# is used to get the number of elements contained in a SortedList. This property returns an integer representing the total count of key-value pairs stored in the collection. Syntax Following is the syntax for using the Count property − int count = sortedList.Count; Parameters The Count property does not take any parameters. It is a read-only property that returns the current number of elements. Return Value The Count property returns an int value representing the number of key-value pairs in the SortedList. Using Count Property ...

Read More

What is use of fluent Validation in C# and how to use in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 2K+ Views

FluentValidation is a powerful .NET library for building strongly-typed validation rules using a fluent interface and lambda expressions. It helps separate validation logic from your domain models, making your code cleaner and more maintainable by centralizing validation rules in dedicated validator classes. The library provides an intuitive way to define complex validation rules with built-in validators, custom validation methods, and detailed error messaging. It's particularly useful in web applications, APIs, and any scenario where robust input validation is required. Installation To use FluentValidation in your project, install the NuGet package − Syntax ...

Read More

What is the usage of ref, out, and in keywords in C#?

Akshay Khot
Akshay Khot
Updated on 17-Mar-2026 635 Views

In C#, method parameters can be passed using different modifiers that control how arguments are handled. The ref, out, and in keywords allow you to pass parameters by reference rather than by value, each serving different purposes and having specific rules. By default, C# passes arguments by value, meaning a copy of the value is created. Changes made inside the method don't affect the original variable. Default Parameter Passing (By Value) Value Types When passing value types, a copy is made and modifications inside the method don't affect the original variable − using System; ...

Read More

TimeSpan.Subtract() Method in C#

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

The TimeSpan.Subtract() method in C# returns a new TimeSpan object whose value is the difference between the current instance and the specified TimeSpan object. This method is useful for calculating time differences in applications dealing with durations and intervals. Syntax Following is the syntax for the TimeSpan.Subtract() method − public TimeSpan Subtract(TimeSpan span); Parameters span − The TimeSpan object to subtract from the current instance. Return Value Returns a new TimeSpan object that represents the time interval difference. If the subtracted value is greater than the current ...

Read More

Check whether a Hashtable contains a specific key or not in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 201 Views

The Hashtable class in C# provides the Contains() method to check whether a specific key exists in the collection. This method returns true if the key is found, and false otherwise. Syntax Following is the syntax for checking if a Hashtable contains a specific key − bool result = hashtable.Contains(key); Parameters key − The key to search for in the Hashtable. This parameter is of type Object. Return Value The Contains() method returns a bool value − true if the Hashtable contains the specified ...

Read More

ListDictionary Class in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 457 Views

The ListDictionary class in C# implements the IDictionary interface using a singly linked list. It is optimized for small collections and is recommended for collections that typically contain fewer than 10 items. For larger collections, it's better to use Hashtable or Dictionary for better performance. Syntax Following is the syntax for creating a ListDictionary − ListDictionary dict = new ListDictionary(); dict.Add(key, value); Key Properties Property Description Count Gets the number of key/value pairs contained in the ListDictionary. IsFixedSize Gets a value indicating whether the ...

Read More

C# SortedDictionary.Add() Method

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 238 Views

The SortedDictionary.Add() method in C# is used to add an element with the specified key and value into the SortedDictionary. Unlike regular dictionaries, SortedDictionary maintains elements in sorted order based on the keys. Syntax Following is the syntax for the Add() method − public void Add(TKey key, TValue value); Parameters key − The key of the element to add. Cannot be null. value − The value of the element to add. Can be null if TValue is a reference type. Return Value This method does not return a value. ...

Read More

Convert Queue To array in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 395 Views

Converting a queue to an array in C# is accomplished using the ToArray() method, which is available for the Queue generic collection. This method creates a new array containing all elements from the queue in the same order they were added (FIFO - First In, First Out). Syntax Following is the syntax for converting a queue to an array − T[] array = queue.ToArray(); Where T is the type of elements in the queue, and queue is the Queue instance. Return Value The ToArray() method returns a new array of type T[] ...

Read More

C# Program to Show the Use of GetEnvironmentVariable() Method of Environment Class

Sabid Ansari
Sabid Ansari
Updated on 17-Mar-2026 8K+ Views

The GetEnvironmentVariable() method of the Environment class in C# is used to retrieve the value of an environment variable. This method is essential for accessing system-wide and user-specific environment variables such as PATH, TEMP, or custom variables set by applications. Syntax Following is the basic syntax for the GetEnvironmentVariable() method − public static string GetEnvironmentVariable(string variable) There is also an overloaded version that accepts an EnvironmentVariableTarget parameter − public static string GetEnvironmentVariable(string variable, EnvironmentVariableTarget target) Parameters variable − A string containing the name of the environment variable. target ...

Read More

SortedDictionary.Clear() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 140 Views

The SortedDictionary.Clear() method in C# is used to remove all key-value pairs from the SortedDictionary. This method provides an efficient way to empty the entire collection in a single operation. Syntax Following is the syntax for the Clear() − public void Clear(); Parameters This method takes no parameters. Return Value This method does not return any value (void). Using Clear() Method with Electronic Items The following example demonstrates how Clear() removes all items from the SortedDictionary − using System; using System.Collections.Generic; public class Demo { ...

Read More
Showing 1021–1030 of 25,467 articles
« Prev 1 101 102 103 104 105 2547 Next »
Advertisements