Csharp Articles

Page 115 of 196

What is a managed code in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 492 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 266 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 795 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 534 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

Large Fibonacci Numbers in C#

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

To display large Fibonacci numbers in C#, we need to handle numbers that exceed the range of standard integer types. The Fibonacci sequence grows exponentially, so after just 40-50 terms, the values become too large for int or even long data types. For truly large Fibonacci numbers, we use the BigInteger class from System.Numerics, which can handle arbitrarily large integers without overflow. Syntax Following is the basic syntax for generating Fibonacci numbers − int val1 = 0, val2 = 1, val3; for (int i = 2; i < n; i++) { val3 ...

Read More

Lambda Expressions in C#

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

A lambda expression in C# is an anonymous function that provides a concise way to write inline functions. Lambda expressions use the => operator, read as "goes to", which separates the input parameters from the expression body. Lambda expressions are commonly used with LINQ methods, event handlers, and delegates to create short, readable code without defining separate methods. Syntax Following is the basic syntax for lambda expressions − (input-parameters) => expression For single parameter, parentheses are optional − x => x * 2 For multiple statements, use curly braces ...

Read More
Showing 1141–1150 of 1,951 articles
« Prev 1 113 114 115 116 117 196 Next »
Advertisements