Server Side Programming Articles

Page 838 of 2109

Understanding IndexOutOfRangeException Exception in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 294 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 381 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

Tuple Rest Property in C#

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

The Rest property in C# tuples allows you to create tuples with eight or more elements by nesting additional tuple objects. When a tuple has more than seven elements, the eighth and subsequent elements are stored in the Rest property as a nested tuple. Syntax The general structure for an 8-element tuple using the Rest property is − Tuple Where TRest is another tuple type containing the remaining elements. You can create such tuples using Tuple.Create() − var myTuple = Tuple.Create(item1, item2, item3, item4, item5, item6, item7, item8); How the ...

Read More

C# Program to get the type of the specified Enumeration

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

Use the GetType() method to get the type of the specified enumeration in C#. This method returns a Type object that represents the actual enumeration type, which is useful for reflection, debugging, and type checking operations. When working with enumeration values, you can retrieve both the enumeration type and its underlying type using built-in methods provided by the Enum class and Type class. Syntax Following is the syntax for getting the type of an enumeration − Type enumType = enumValue.GetType(); To get the underlying type of an enumeration − Type underlyingType ...

Read More

C# Enum GetValues Method

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

The Enum.GetValues() method in C# retrieves an array containing the values of all constants in a specified enumeration. This method is useful when you need to iterate through all enum values dynamically or perform operations on the entire set of enum values. Syntax Following is the syntax for the Enum.GetValues() method − public static Array GetValues(Type enumType) Parameters enumType − The Type of the enumeration whose values you want to retrieve. Return Value Returns an Array containing the values of the constants in the specified enumeration. Using GetValues() ...

Read More

Complex Numbers in C#

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

A complex number in C# consists of two components: a real part and an imaginary part. For example, in the complex number 7+5i, the real part is 7 and the imaginary part is 5 (the coefficient of i). C# allows you to create custom data structures to represent complex numbers using struct and implement mathematical operations using operator overloading. Syntax Following is the syntax for creating a complex number structure − public struct Complex { public double real; public double imaginary; public ...

Read More

Compound assignment operators in C#

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

Compound assignment operators in C# provide a shorter syntax to perform an operation and assign the result back to the same variable. These operators combine arithmetic, bitwise, or shift operations with assignment in a single step. For example, x += 5 is equivalent to x = x + 5, but more concise and readable. Syntax The general syntax for compound assignment operators is − variable operator= value; This is equivalent to − variable = variable operator value; Types of Compound Assignment Operators Operator Name Equivalent ...

Read More

Constructors in C#

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

A constructor in C# is a special method that gets invoked automatically when an object is created. The constructor has the same name as the class and is used to initialize the object's state. Constructors do not have a return type, not even void. Syntax Following is the basic syntax for declaring a constructor − public class ClassName { public ClassName() { // constructor body } } Types of Constructors C# supports several types of constructors − Default ...

Read More

Default constructor in C#

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

A default constructor in C# is a constructor that takes no parameters. When you create an object of a class, the constructor is automatically invoked. The constructor has the same name as the class and is used to initialize the object. If you don't explicitly define any constructor in your class, C# automatically provides a default constructor. However, if you define any parameterized constructor, you must explicitly define the default constructor if you want to use it. Syntax Following is the syntax for declaring a default constructor − public class ClassName { ...

Read More

Difference between Abstract Class and Interface in C#

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

Both abstract classes and interfaces in C# define contracts for derived classes to implement, but they serve different purposes and have distinct characteristics. An interface defines a contract with method signatures that implementing classes must provide, while an abstract class can provide both abstract methods and concrete implementations that derived classes inherit. Understanding the key differences helps you choose the right approach for your object-oriented design needs. Syntax Following is the syntax for declaring an interface − public interface IInterfaceName { void Method1(); int Property1 { get; ...

Read More
Showing 8371–8380 of 21,090 articles
« Prev 1 836 837 838 839 840 2109 Next »
Advertisements