Server Side Programming Articles

Page 834 of 2109

Get bounds of a C# three-dimensional array

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

To get the bounds of a three-dimensional array in C#, use the GetUpperBound() and GetLowerBound() methods. These methods return the highest and lowest indices for a specified dimension of the array. The parameter passed to these methods specifies the dimension (0, 1, or 2 for a three-dimensional array). Understanding array bounds is crucial for safe array traversal and avoiding index out-of-range exceptions. Syntax Following is the syntax for getting array bounds − array.GetUpperBound(dimension) array.GetLowerBound(dimension) Parameters dimension: An integer specifying the dimension of the array (0-based indexing). Return ...

Read More

ArgumentNullException in C#

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

The ArgumentNullException is thrown when a null reference is passed to a method that does not accept it as a valid argument. This exception is part of the System namespace and helps prevent null reference errors by catching them early. This exception commonly occurs when methods expect non-null parameters but receive null values instead. It provides clear error messages indicating which parameter was null. Syntax Following is the syntax for throwing ArgumentNullException − throw new ArgumentNullException(paramName); throw new ArgumentNullException(paramName, "Custom message"); Following is the syntax for handling ArgumentNullException − try { ...

Read More

C# Program to convert an Int32 value to a decimal

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

To convert an Int32 value to a decimal in C#, you can use the Convert.ToDecimal() method or implicit casting. An Int32 represents a 32-bit signed integer, while decimal provides higher precision for financial and monetary calculations. Syntax Following is the syntax for converting Int32 to decimal using Convert.ToDecimal() − decimal result = Convert.ToDecimal(intValue); Following is the syntax for implicit casting − decimal result = intValue; Using Convert.ToDecimal() Method The Convert.ToDecimal() method explicitly converts an Int32 value to a decimal type − using System; public class Demo ...

Read More

C# Program to convert a Byte value to an Int32 value

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

To convert a byte value to an int value in C#, you can use the Convert.ToInt32() method or implicit conversion. Since a byte (8-bit unsigned integer) can always fit within an int (32-bit signed integer), the conversion is straightforward and safe. An Int32 represents a 32-bit signed integer that can store values from -2, 147, 483, 648 to 2, 147, 483, 647, while a byte stores values from 0 to 255. Syntax Using Convert.ToInt32() method − int result = Convert.ToInt32(byteValue); Using implicit conversion − int result = byteValue; Using ...

Read More

C# Program to convert a Double value to an Int64 value

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

To convert a Double value to an Int64 value, use the Convert.ToInt64() method. This method performs a rounded conversion from a 64-bit floating-point number to a 64-bit signed integer. Int64 represents a 64-bit signed integer and is equivalent to the long data type in C#. The conversion truncates the decimal portion and rounds to the nearest integer value. Syntax Following is the syntax for converting a double to Int64 − long result = Convert.ToInt64(doubleValue); Parameters doubleValue − A double-precision floating-point number to be converted. Return Value Returns a ...

Read More

C# Program to convert a Double to an Integer Value

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

To convert a double value to an integer value in C#, you can use several methods. The most common approach is using the Convert.ToInt32() method, which performs rounded conversion, or explicit casting for truncation. The Int32 data type represents a 32-bit signed integer that can store values from -2, 147, 483, 648 to 2, 147, 483, 647. Syntax Following are the different syntaxes for converting double to integer − // Using Convert.ToInt32() - rounds to nearest integer int result = Convert.ToInt32(doubleValue); // Using explicit casting - truncates decimal part int result = (int)doubleValue; ...

Read More

Implicit conversion from Byte to Decimal in C#

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

Byte represents an 8-bit unsigned integer that can store values from 0 to 255. Implicit conversion from byte to decimal is possible in C# because there is no loss of data − all byte values can be exactly represented as decimal values. Implicit conversion happens automatically without requiring any casting operator or explicit conversion method. Syntax The syntax for implicit conversion from byte to decimal is − byte byteValue = value; decimal decimalValue = byteValue; // Implicit conversion How Implicit Conversion Works When you assign a byte value to a decimal variable, ...

Read More

Implicit conversion from 32-bit unsigned integer (UInt) to Decimal in C#

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

Implicit conversion from a 32-bit unsigned integer (uint) to decimal in C# happens automatically when you assign a uint value to a decimal variable. This conversion is considered safe because decimal can represent all possible uint values without any loss of precision. Syntax Following is the syntax for implicit conversion from uint to decimal − uint uintValue = someValue; decimal decimalValue = uintValue; // implicit conversion How It Works The C# compiler automatically performs this conversion because: uint ranges from 0 to 4, 294, 967, 295 decimal can ...

Read More

C# Average Method

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

The Average() method in C# calculates the arithmetic mean of a sequence of numeric values. This method is part of LINQ (Language Integrated Query) and can be used with arrays, lists, and other enumerable collections. The Average() method has multiple overloads to work with different numeric types including int, double, decimal, float, and their nullable counterparts. Syntax Following is the basic syntax for the Average() method − public static double Average(this IEnumerable source) public static double Average(this IEnumerable source) public static decimal Average(this IEnumerable source) Parameters source − An enumerable ...

Read More

C# Cast method

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

The Cast() method in C# is a LINQ extension method used to cast each element in a collection from one type to another. It is particularly useful when working with collections of object type that need to be converted to a specific type for further processing. Syntax Following is the syntax for the Cast() method − public static IEnumerable Cast(this IEnumerable source) Parameters source − The collection containing elements to be cast. TResult − The target type to cast elements to. Return Value Returns an IEnumerable containing each element ...

Read More
Showing 8331–8340 of 21,090 articles
« Prev 1 832 833 834 835 836 2109 Next »
Advertisements