Server Side Programming Articles

Page 835 of 2109

C# Linq Contains Method

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 3K+ Views

The Contains() method in LINQ is used to check whether a sequence contains a specific element. It returns true if the element is found, otherwise false. This method works with any IEnumerable collection including arrays, lists, and queryable sequences. Syntax Following is the syntax for using Contains() with collections − bool result = collection.Contains(element); Following is the syntax for using Contains() with queryable sequences − bool result = collection.AsQueryable().Contains(element); Parameters element − The value to locate in the sequence. Return Value Returns true if the ...

Read More

C# Program to search for a string in an array of strings

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 3K+ Views

Searching for a string in an array of strings is a common programming task. C# provides several methods to accomplish this, with the most straightforward being the LINQ Contains() method. This method returns a boolean value indicating whether the specified string exists in the array. Syntax Following is the syntax for using Contains() method to search in an array − array.Contains(searchString) You can also use it with AsQueryable() for LINQ queries − array.AsQueryable().Contains(searchString) Using LINQ Contains() Method The simplest approach is to use the LINQ Contains() method which returns ...

Read More

C# Linq Count method

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 749 Views

The Count method in LINQ returns the number of elements in a sequence. It is one of the most commonly used LINQ methods for determining collection size and can be used with arrays, lists, and any IEnumerable collection. Syntax Following is the syntax for the basic Count method − int count = collection.Count(); Following is the syntax for Count with a predicate condition − int count = collection.Count(predicate); Using Count() on Arrays and Collections The Count method can be applied to any collection that implements IEnumerable. Here's how to ...

Read More

C# DefaultIfEmpty Method

Samual Sam
Samual Sam
Updated on 17-Mar-2026 345 Views

The DefaultIfEmpty method in C# is a LINQ extension method used to handle empty collections gracefully. Instead of returning an empty sequence that might cause issues in further operations, it returns a sequence containing a single default value when the original collection is empty. Syntax Following is the syntax for the DefaultIfEmpty method − public static IEnumerable DefaultIfEmpty( this IEnumerable source ) public static IEnumerable DefaultIfEmpty( this IEnumerable source, TSource defaultValue ) Parameters source − The sequence to return ...

Read More

C# OverflowException

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 1K+ Views

The OverflowException in C# is thrown when an arithmetic operation results in a value that exceeds the range of the target data type. This commonly occurs during type conversions, arithmetic operations, or when parsing strings that contain values outside the acceptable range. Common Scenarios OverflowException is typically thrown in the following situations − Converting a string to an integer when the value exceeds int.MaxValue or int.MinValue Arithmetic operations that result in overflow (in checked context) Casting between numeric types where the source value is too large for the target type ...

Read More

C# Decimal ("D") Format Specifier

George John
George John
Updated on 17-Mar-2026 2K+ Views

The "D" (decimal) format specifier in C# is used to format integer types as a string of decimal digits (0-9). It displays the number with optional zero-padding to achieve a specified minimum length. Syntax Following is the syntax for the "D" format specifier − number.ToString("D") // Basic decimal format number.ToString("Dn") // Decimal with minimum n digits Where n is the minimum number of digits. If the number has fewer digits, it will be padded with leading zeros. Parameters ...

Read More

Represent Int64 as a String in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 353 Views

The Int64 data type in C# represents a 64-bit signed integer that can hold values from -9, 223, 372, 036, 854, 775, 808 to 9, 223, 372, 036, 854, 775, 807. Converting an Int64 to a string is a common operation that can be accomplished using several methods, with ToString() being the most straightforward approach. Syntax The basic syntax for converting an Int64 to string using ToString() method − long variable = value; string result = variable.ToString(); You can also use format specifiers with ToString() − string result = variable.ToString("format"); ...

Read More

Represent Int64 as a Hexadecimal String in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 2K+ Views

To represent Int64 as a hexadecimal string in C#, use the Convert.ToString() method and set the base as 16 for hexadecimal conversion. Int64 represents a 64-bit signed integer that can hold values from -9, 223, 372, 036, 854, 775, 808 to 9, 223, 372, 036, 854, 775, 807. Syntax Following is the syntax for converting Int64 to hexadecimal string − Convert.ToString(longValue, 16) You can also use the ToString() method with format specifiers − longValue.ToString("X") // Uppercase hex longValue.ToString("x") // Lowercase hex Using Convert.ToString() Method The ...

Read More

The "0" custom format specifier in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 2K+ Views

The "0" custom format specifier in C# is a zero placeholder that ensures a digit appears in each specified position. If the value being formatted has a digit in that position, it displays the digit; otherwise, it displays a zero. This format specifier is particularly useful for creating fixed-width numeric displays, padding numbers with leading zeros, or ensuring decimal places are always shown. Syntax Following is the syntax for using the "0" custom format specifier − number.ToString("000") // For integers with leading zeros number.ToString("0.00") // For decimals with ...

Read More

The "#" custom specifier in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 274 Views

The # custom format specifier in C# serves as a digit placeholder symbol in numeric formatting. It displays a digit only if one exists at that position, making it useful for creating flexible number formats that suppress unnecessary leading and trailing zeros. Syntax Following is the syntax for using the # format specifier − number.ToString("#formatPattern") String.Format("{0:#formatPattern}", number) How It Works When formatting a number, the # symbol represents an optional digit position. If the value has a digit at that position, it displays the digit. If not, nothing is displayed for that position. ...

Read More
Showing 8341–8350 of 21,090 articles
« Prev 1 833 834 835 836 837 2109 Next »
Advertisements