Csharp Articles

Page 162 of 196

Convert.ToBoolean Method in C#

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

The Convert.ToBoolean method in C# converts a specified value to an equivalent Boolean value. This method follows specific rules depending on the input type − numeric types return false if zero, true otherwise; string values are parsed based on their content. Syntax Following is the syntax for the Convert.ToBoolean method − public static bool ToBoolean(object value); public static bool ToBoolean(string value); public static bool ToBoolean(int value); public static bool ToBoolean(double value); // Other overloads for different data types Parameters value − The value to convert to a Boolean. Can be a ...

Read More

Convert.ToByte Method in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 1K+ Views

The Convert.ToByte method in C# converts a specified value to an 8-bit unsigned integer (byte). A byte can hold values from 0 to 255, making it useful for representing small integers, ASCII characters, and binary data. This method provides a safe way to convert various data types to byte values, with built-in overflow checking that throws an OverflowException if the value is outside the valid byte range. Syntax Following are the common overloads of the Convert.ToByte method − Convert.ToByte(object value) Convert.ToByte(string value) Convert.ToByte(char value) Convert.ToByte(int value) Convert.ToByte(double value) Parameters value − ...

Read More

Convert.ToUInt64 Method in C#

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

The Convert.ToUInt64() method in C# converts a specified value to a 64-bit unsigned integer (ulong). This method accepts various data types and returns their equivalent ulong representation. Syntax Following is the syntax for the Convert.ToUInt64() method − public static ulong ToUInt64(object value) public static ulong ToUInt64(string value) public static ulong ToUInt64(char value) public static ulong ToUInt64(int value) public static ulong ToUInt64(double value) Parameters value − The value to convert. Can be of type object, string, char, numeric types, or other convertible types. Return Value Returns a 64-bit ...

Read More

C# Linq Last() Method

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

The LINQ Last() method in C# returns the last element from a sequence. It throws an exception if the sequence is empty, making it suitable when you are certain the collection contains elements. Syntax Following is the syntax for the Last() method − public static TSource Last(this IEnumerable source); public static TSource Last(this IEnumerable source, Func predicate); Parameters source − The sequence to return the last element from. predicate − (Optional) A function to test each element for a condition. Return Value Returns the last ...

Read More

C# Enum Equals Method

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

The Equals() method in C# is used to compare enum values for equality. It returns true if both enum values have the same underlying value, and false otherwise. Syntax Following is the syntax for using the Equals() method with enums − enumValue1.Equals(enumValue2) Parameters enumValue2 − The enum value to compare with the current enum value Return Value The method returns a bool value − true if both enum values are equal false if the enum values are different ...

Read More

Convert.ToUInt32 Method in C#

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

The Convert.ToUInt32 method in C# converts a specified value to a 32-bit unsigned integer (uint). This method can convert various data types including strings, integers, floating-point numbers, and other numeric types to an unsigned 32-bit integer. The uint data type can hold values from 0 to 4, 294, 967, 295, making it suitable for scenarios where you need positive integers only with a larger range than regular int. Syntax Following are the common overloads of the Convert.ToUInt32 method − Convert.ToUInt32(string value) Convert.ToUInt32(int value) Convert.ToUInt32(double value) Convert.ToUInt32(object value) Parameters value − The ...

Read More

C# Enum Format Method

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

The Enum.Format method in C# converts the value of a specified enumerated type to its equivalent string representation according to the specified format. This method provides flexible formatting options including decimal, hexadecimal, and name representations. Syntax Following is the syntax for the Enum.Format method − public static string Format(Type enumType, object value, string format) Parameters enumType − The enumeration type of the value to convert. value − The value to convert. format − The output format to use. Common formats are "G" (name), "D" (decimal), "X" (hexadecimal), and "F" (name if defined, ...

Read More

C# Program to return specified number of elements from the beginning of a sequence

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

The Take() method in C# is a LINQ extension method that returns a specified number of elements from the beginning of a sequence. This method is particularly useful when you need to retrieve only the first few elements from a collection, especially after sorting or filtering operations. Syntax Following is the syntax for the Take() method − public static IEnumerable Take( this IEnumerable source, int count ) Parameters source − The sequence to return elements from. count − The number of elements to return ...

Read More

Understanding IndexOutOfRangeException Exception in C#

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

The IndexOutOfRangeException is a common runtime exception in C# that occurs when you attempt to access an array element using an index that is outside the valid range of indices for that array. This exception helps prevent memory corruption by catching invalid array access attempts. Arrays in C# are zero-indexed, meaning the first element is at index 0, and the last element is at index length - 1. Attempting to access an index less than 0 or greater than or equal to the array length will throw this exception. When IndexOutOfRangeException Occurs This exception is thrown in ...

Read More

C# Program to access tuple elements

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

In C#, tuples are data structures that can hold multiple values of different types. Once you create a tuple, you can access its elements using the Item properties, where each element is numbered starting from Item1. Syntax Following is the syntax for creating a tuple using Tuple.Create() − var tupleName = Tuple.Create(value1, value2, value3, ...); Following is the syntax for accessing tuple elements − tupleName.Item1 // First element tupleName.Item2 // Second element tupleName.Item3 // Third element Using Item Properties to Access Elements Create a tuple with ...

Read More
Showing 1611–1620 of 1,951 articles
« Prev 1 160 161 162 163 164 196 Next »
Advertisements