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 836 of 2109
C# Program to find a key in Dictionary
In C#, a Dictionary is a collection that stores key-value pairs. To check if a specific key exists in a Dictionary, you can use the ContainsKey() method, which returns true if the key is found and false otherwise. Syntax Following is the syntax for using the ContainsKey() method − bool result = dictionary.ContainsKey(key); Parameters key − The key to locate in the Dictionary. Return Value Returns true if the Dictionary contains an element with the specified key; otherwise, false. Using ContainsKey() Method The most straightforward way to ...
Read More"." custom specifier in C#
The "." custom format specifier in C# adds a localized decimal separator into the output string. It determines the exact position where the decimal point will appear in the formatted numeric value. The first period in the format string determines the location of the decimal separator in the formatted value. Any additional periods are ignored and treated as literal characters. Syntax Following is the syntax for using the "." custom format specifier − number.ToString("format_with_decimal_point") String.Format("format_with_decimal_point", number) Where the format string contains a period (.) to specify decimal separator placement. How It Works ...
Read MoreSize of a Three-dimensional array in C#
To get the size of a three-dimensional array in C#, you can use the GetLength() method to retrieve the size of individual dimensions, or the Length property to get the total number of elements across all dimensions. Syntax Following is the syntax for getting the size of specific dimensions − array.GetLength(dimensionIndex) Following is the syntax for getting the total number of elements − array.Length Parameters dimensionIndex − A zero-based integer representing the dimension index (0 for first dimension, 1 for second dimension, 2 for third dimension). ...
Read MoreFormatException in C#
A FormatException is thrown when the format of an argument is invalid or cannot be converted to the expected data type. This commonly occurs when attempting to parse a string that doesn't match the expected format for numeric or date types. Common Scenarios FormatException typically occurs in these situations − Parsing a non-numeric string as a number using int.Parse(), double.Parse(), etc. Converting a string with decimal points to an integer Parsing invalid date formats using DateTime.Parse() Using incorrect format specifiers in string formatting Using int.Parse() with ...
Read MoreC# Linq Except Method
The Except() method in LINQ is used to find the set difference between two collections. It returns elements from the first collection that are not present in the second collection, effectively performing a set subtraction operation. Syntax Following is the syntax for the Except() method − public static IEnumerable Except( this IEnumerable first, IEnumerable second ) With custom equality comparer − public static IEnumerable Except( this IEnumerable first, IEnumerable second, IEqualityComparer comparer ...
Read MoreC# Linq ElementAt Method
The ElementAt() method in C# LINQ returns the element at a specified index position in a sequence. It is part of the LINQ extension methods and can be used with any IEnumerable collection. The ElementAt() method throws an ArgumentOutOfRangeException if the index is out of bounds. For safer access, you can use ElementAtOrDefault(), which returns the default value for the type if the index is invalid. Syntax Following is the syntax for the ElementAt() method − public static TSource ElementAt(this IEnumerable source, int index) Following is the syntax for the ElementAtOrDefault() method − ...
Read MoreSortable ("s") Format Specifier in C#
The Sortable ("s") format specifier in C# represents a standardized date and time format that produces ISO 8601-compliant strings. This format is particularly useful for sorting dates chronologically as strings and for data interchange between different systems. The "s" format specifier is defined by the DateTimeFormatInfo.SortableDateTimePattern property and follows a consistent pattern regardless of the current culture settings. Syntax The sortable format specifier uses the following syntax − DateTime.ToString("s") This corresponds to the custom format pattern − yyyy'-'MM'-'dd'T'HH':'mm':'ss Format Pattern Breakdown Sortable Format Pattern: ...
Read MoreC# Linq First() Method
The First() method in C# LINQ is used to return the first element from a collection such as arrays, lists, or any IEnumerable sequence. It throws an exception if the collection is empty. Syntax Following is the syntax for the First() method − collection.First() collection.First(predicate) Parameters predicate (optional) − A function to test each element for a condition. Return Value Returns the first element in the collection or the first element that satisfies the condition. Throws InvalidOperationException if no element is found. Using First() Without Predicate The ...
Read MoreC# Math.DivRem Method
The Math.DivRem method in C# performs integer division and returns both the quotient and remainder in a single operation. This is more efficient than performing separate division and modulo operations when you need both results. Syntax Following is the syntax for the Math.DivRem method − public static int Math.DivRem(int a, int b, out int result); public static long Math.DivRem(long a, long b, out long result); Parameters a − The dividend (number to be divided) b − The divisor (number to divide by) result − An out parameter that receives the remainder ...
Read MoreRepresent Int32 as a String in C#
The Int32 type in C# represents a 32-bit signed integer. To convert an Int32 value to its string representation, you can use the ToString() method. This method converts the numeric value into a readable string format. Syntax Following is the syntax for converting an Int32 to string using ToString() − int number = value; string result = number.ToString(); You can also use format specifiers with ToString() − string result = number.ToString("format"); Using ToString() Method Basic Conversion Example The simplest way to convert an Int32 to string is using ...
Read More