Server Side Programming Articles

Page 790 of 2109

Chained Exceptions in C#

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

Chained exceptions in C# allow you to preserve the original exception information while throwing a new exception. This creates a chain of exceptions where each exception wraps the previous one, maintaining the complete error context throughout the call stack. When an exception occurs deep in your application, chained exceptions help maintain the full error history by wrapping the original exception inside a new one using the innerException parameter of the Exception constructor. Syntax Following is the syntax for creating a chained exception − try { // code that might throw exception } ...

Read More

How to call Math Operations using Delegates in C#?

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

To understand how to call Math Operations using Delegates in C#, let us see an example wherein we will perform mathematical operations like division, multiplication, and addition using delegates. A delegate in C# is a type that represents references to methods with a specific signature. Syntax Following is the syntax for declaring a delegate that can reference mathematical methods − delegate returnType DelegateName(parameters); Following is the syntax for assigning methods to a delegate − DelegateName delegateInstance = MethodName; // or DelegateName delegateInstance = new DelegateName(MethodName); Using Delegates for Basic Math ...

Read More

What is a managed code in C#?

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

Managed code in C# is code whose execution is managed by the Common Language Runtime (CLR). The CLR provides automatic memory management, type safety, exception handling, and garbage collection. When you write C# code, it gets compiled into Intermediate Language (IL) code, which is then executed by the CLR. Unlike unmanaged code (such as C/C++), managed code runs within the .NET runtime environment, which handles low-level operations automatically. This makes development safer and more efficient by reducing common programming errors like memory leaks and buffer overflows. How Managed Code Works The execution process of managed code follows ...

Read More

How to perform Division of Exponents of Same Base using C#?

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

When dividing exponents with the same base, we use the mathematical rule: a^m ÷ a^n = a^(m-n). This means we subtract the exponent in the denominator from the exponent in the numerator while keeping the base unchanged. In C#, we can implement this rule by subtracting the exponents and then using Math.Pow() to calculate the final result. Mathematical Rule The division rule for exponents with the same base is − a^m ÷ a^n = a^(m-n) For example: 10^10 ÷ 10^8 = 10^(10-8) = 10^2 = 100 Division of ...

Read More

Checked vs Unchecked Exceptions in C#

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

The checked and unchecked keywords in C# control whether arithmetic operations throw exceptions when overflow occurs. By default, C# ignores arithmetic overflow in most contexts, but you can explicitly enable or disable overflow checking using these keywords. In a checked context, arithmetic overflow throws an OverflowException. In an unchecked context, overflow is ignored and the result wraps around to the valid range. Syntax Following is the syntax for checked operations − int result = checked(expression); checked { // multiple statements } Following is the syntax for unchecked operations − ...

Read More

What is the difference between list and dictionary in C#?

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

A List and Dictionary are both generic collections in C#, but they serve different purposes. A List stores elements in a sequential order with index-based access, while a Dictionary stores key-value pairs for fast lookups. Understanding when to use each collection type is crucial for writing efficient C# applications. Lists are ideal for ordered data where you need to access elements by position, while dictionaries are perfect for mapping relationships and quick key-based retrieval. Syntax Following is the syntax for creating a List − List listName = new List(); // or with initialization List listName ...

Read More

How to perform Matrix Addition using C#?

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

Matrix addition in C# involves adding corresponding elements from two matrices of the same dimensions. The matrices must have identical rows and columns for addition to be possible. The result is a new matrix where each element is the sum of the corresponding elements from the input matrices. Syntax Following is the basic syntax for matrix addition − int[, ] result = new int[rows, columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { ...

Read More

Print a 2 D Array or Matrix in C#

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

A 2D array or matrix in C# is a data structure that stores elements in rows and columns. To print a 2D array, you need to use nested loops to iterate through each row and column, displaying the elements in a formatted manner. Syntax Following is the syntax for declaring a 2D array − dataType[, ] arrayName = new dataType[rows, columns]; Following is the syntax for printing a 2D array using nested loops − for (int i = 0; i < rows; i++) { for (int j = ...

Read More

Quickly convert Decimal to other bases in C#

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

Converting decimal numbers to other bases in C# can be efficiently accomplished using a Stack data structure. The stack naturally handles the reversal of digits that occurs during the conversion process, making it an ideal choice for base conversion algorithms. How It Works The conversion process involves repeatedly dividing the decimal number by the target base and storing the remainders. Since division produces digits in reverse order, a stack helps retrieve them in the correct sequence: Divide the decimal number by the target base Push the remainder onto the stack Update the number to the quotient ...

Read More

How to print all the Armstrong Numbers from 1 to 1000 using C#?

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

An Armstrong number (also called a narcissistic number) is a number that equals the sum of its own digits raised to the power of the number of digits. For 3-digit numbers, each digit is cubed and summed. For example, 153 is an Armstrong number because 1³ + 5³ + 3³ = 1 + 125 + 27 = 153. To find all Armstrong numbers from 1 to 1000, we need to check each number by extracting its digits, calculating the sum of cubes, and comparing it with the original number. Algorithm The steps to identify Armstrong numbers are ...

Read More
Showing 7891–7900 of 21,090 articles
« Prev 1 788 789 790 791 792 2109 Next »
Advertisements