Csharp Articles

Page 154 of 196

Clear a Linked List in C#

George John
George John
Updated on 17-Mar-2026 247 Views

The Clear() method in C# is used to remove all nodes from a LinkedList. This method provides an efficient way to empty the entire linked list in a single operation, resetting the Count property to zero. Syntax Following is the syntax for the Clear() − linkedList.Clear(); Parameters The Clear() method takes no parameters. Return Value The Clear() method does not return any value. It is a void method that modifies the linked list in-place. LinkedList Clear() Operation Before Clear(): ...

Read More

Long Date ("D") Format Specifier in C#

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

The "D" format specifier in C# represents the long date format pattern. It displays dates in a culture-specific long format, showing the full day name, month name, day, and year without time information. The format string is defined by the culture's DateTimeFormatInfo.LongDatePattern property and varies based on the specified culture. Syntax Following is the syntax for using the "D" format specifier − DateTime.ToString("D") DateTime.ToString("D", CultureInfo) The default custom format string for English (US) culture is − dddd, dd MMMM yyyy Using "D" Format with Default Culture Example ...

Read More

How to negate the positive elements of an integer array in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 474 Views

Negating the positive elements of an integer array means converting all positive values to their negative counterparts while leaving negative and zero values unchanged. This operation is useful in various mathematical computations and data processing scenarios. Syntax Following is the basic syntax to check and negate positive elements − if (arr[i] > 0) arr[i] = -arr[i]; A complete loop structure to process all array elements − for (int i = 0; i < arr.Length; i++) { if (arr[i] > 0) ...

Read More

C# Currency ("C") Format Specifier

Samual Sam
Samual Sam
Updated on 17-Mar-2026 33K+ Views

The C format specifier (currency) is used to format numeric values as currency amounts. It automatically applies the appropriate currency symbol, decimal places, and thousands separators based on the current culture settings. Syntax Following is the syntax for using the currency format specifier − value.ToString("C") // Default currency format value.ToString("C3") // Currency with 3 decimal places value.ToString("C", culture) // Currency with specific culture The precision specifier (optional number after C) determines how many decimal ...

Read More

Remove an item from a Hashtable in C#

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

The Hashtable class in C# provides the Remove() method to delete key-value pairs. The method takes the key as a parameter and removes the corresponding entry from the hashtable if it exists. Syntax Following is the syntax for removing an item from a Hashtable − hashtable.Remove(key); Parameters key − The key of the element to remove from the hashtable. Return Value The Remove()

Read More

C# Program to find a key in a Hashtable

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

A Hashtable in C# is a collection of key-value pairs where each key is unique. To check if a specific key exists in a Hashtable, you can use the Contains() method or ContainsKey() method. Syntax Following is the syntax for creating a Hashtable and checking if a key exists − Hashtable hashtable = new Hashtable(); hashtable.Add(key, value); bool exists = hashtable.Contains(key); Alternatively, you can use ContainsKey() method − bool exists = hashtable.ContainsKey(key); Using Contains() Method The Contains() method returns true if the specified key exists in the Hashtable, otherwise ...

Read More

Convert.ToDouble Method in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 11K+ Views

The Convert.ToDouble() method in C# converts a specified value to a double-precision floating-point number. This method is part of the Convert class and can handle various data types including integers, strings, booleans, and other numeric types. Syntax Following is the syntax for the Convert.ToDouble() method − public static double ToDouble(object value) public static double ToDouble(string value) public static double ToDouble(int value) public static double ToDouble(long value) public static double ToDouble(bool value) Parameters value − The value to be converted to a double-precision floating-point number. This can be of various types including object, string, ...

Read More

ContainsKey() method in C#

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

The ContainsKey() method in C# is used to check whether a specific key exists in a Hashtable or other collection types like Dictionary. This method returns true if the key is found, otherwise it returns false. Syntax Following is the syntax for the ContainsKey() method − bool ContainsKey(object key) Parameters key − The key to locate in the collection. Return Value Returns true if the key exists in the collection; otherwise, false. ContainsKey() Method Logic Hashtable ...

Read More

Clear a Hashtable in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 533 Views

The Clear() method in C# is used to remove all key-value pairs from a Hashtable. This method provides an efficient way to empty the entire Hashtable in a single operation, resetting its count to zero while maintaining the original capacity. Syntax Following is the syntax for the Clear()

Read More

C# Program to get distinct element from a sequence

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

The Distinct() method in C# is used to remove duplicate elements from a sequence and return only unique values. This method is part of LINQ (Language Integrated Query) and works with any collection that implements IEnumerable. Syntax Following is the syntax for the Distinct() method − IEnumerable Distinct() IEnumerable Distinct(IEqualityComparer comparer) Parameters comparer (optional) − An IEqualityComparer to compare values for equality. If not provided, the default equality comparer is used. Return Value Returns an IEnumerable containing distinct elements from the source sequence. Using Distinct() with ...

Read More
Showing 1531–1540 of 1,951 articles
« Prev 1 152 153 154 155 156 196 Next »
Advertisements