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
Server Side Programming Articles
Page 829 of 2109
C# Enum ToString() Method
The ToString() method in C# enums converts the enum value to its equivalent string representation. This method provides different formatting options to display enum values as either their names or underlying numeric values. Syntax Following are the common syntax forms for enum ToString() method − enumValue.ToString() // Returns name enumValue.ToString("G") // Returns name (General format) enumValue.ToString("d") // Returns decimal value enumValue.ToString("D") // Returns decimal value Parameters ...
Read MoreC# Enum Parse Method
The Enum.Parse method in C# converts the string representation of an enum constant name or its numeric value into an equivalent enumerated object. This method is essential when you need to convert string data back into strongly-typed enum values. Syntax Following are the main syntax forms for Enum.Parse − // Basic syntax public static object Parse(Type enumType, string value) // With ignore case option public static object Parse(Type enumType, string value, bool ignoreCase) Parameters enumType − The type of the enumeration to parse to value − A string containing the name ...
Read MoreClear a Linked List in C#
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 MoreLong Date ("D") Format Specifier in C#
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 MoreHow to negate the positive elements of an integer array in C#?
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 MoreC# Currency ("C") Format Specifier
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 MoreRemove an item from a Hashtable in C#
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 MoreC# Program to find a key in a Hashtable
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 MoreConvert.ToDouble Method in C#
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 MoreContainsKey() method in C#
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