Articles on Trending Technologies

Technical articles with clear explanations and examples

Decimal.Multiply() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 1K+ Views

The Decimal.Multiply() method in C# is used to multiply two specified decimal values and returns the result as a decimal. This method provides a safe way to perform decimal multiplication while maintaining precision and handling potential overflow conditions. Syntax Following is the syntax − public static decimal Multiply(decimal val1, decimal val2); Parameters val1 − The first decimal value (multiplicand). val2 − The second decimal value (multiplier). Return Value Returns a decimal value that represents the product of val1 and val2. Using Decimal.Multiply() for Basic ...

Read More

How to declare and initialize a dictionary in C#?

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

A Dictionary in C# is a collection that stores key-value pairs, where each key must be unique. It is part of the System.Collections.Generic namespace and provides fast lookups based on keys. Syntax Following is the syntax for declaring and initializing a Dictionary − Dictionary dictionaryName = new Dictionary(); Where TKey is the type of the key and TValue is the type of the value. You can also use the interface type for more flexibility − IDictionary dictionaryName = new Dictionary(); Using Dictionary.Add() Method The Add() method allows you ...

Read More

Optimization Tips for C# Code

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

C# code optimization involves writing efficient code that executes faster and uses memory more effectively. Here are essential optimization tips that can significantly improve your application's performance. Prefer Generic Collections Over Non-Generic Use List instead of ArrayList whenever possible. Generic collections provide type safety and better performance by avoiding boxing and unboxing operations − using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; class Program { public static void Main() { // Inefficient - ArrayList with boxing ArrayList arrayList = new ...

Read More

How to convert Decimal to Binary using C#?

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

Converting decimal numbers to binary in C# can be accomplished using the division and modulus operators. This process involves repeatedly dividing the decimal number by 2 and collecting the remainders, which form the binary representation when reversed. The algorithm works by dividing the decimal value by 2, storing the remainder (which is always 0 or 1), and continuing until the quotient becomes 0. The binary representation is formed by reading the remainders in reverse order. Algorithm The conversion process follows these steps − Divide the decimal number by 2 Store the remainder ...

Read More

C# Program to find the smallest element from an array using Lambda Expressions

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

Lambda expressions in C# provide a concise way to write anonymous functions. When combined with LINQ methods like Min(), they offer powerful tools for array operations. This article demonstrates how to find the smallest element from an array using lambda expressions. Syntax The basic syntax for using Min() with lambda expressions − array.Min() // finds minimum value directly array.Min(element => expression) // finds minimum based on expression Using Min() Without Lambda Expression For ...

Read More

Implicit conversion from 8-bit signed integer (SByte) to Decimal in C#

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

SByte represents an 8-bit signed integer with values ranging from -128 to 127. C# allows implicit conversion from sbyte to decimal because this conversion is always safe and does not result in data loss. Syntax Following is the syntax for implicit conversion from sbyte to decimal − sbyte sbyteValue = value; decimal decimalValue = sbyteValue; // implicit conversion How It Works The conversion happens automatically without requiring explicit casting because decimal can represent all possible sbyte values without precision loss. The 8-bit signed integer is widened to fit into the 128-bit decimal ...

Read More

What are abstract classes in C#?

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

An abstract class in C# is a class that cannot be instantiated directly and contains one or more abstract methods that must be implemented by derived classes. Abstract classes provide a common base with shared functionality while requiring derived classes to implement specific methods with their own specialized behavior. Abstract classes are declared using the abstract keyword and serve as blueprints for related classes that share common characteristics but need different implementations for certain operations. Syntax Following is the syntax for declaring an abstract class with abstract methods − abstract class ClassName { ...

Read More

C# program to multiply two matrices

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

Matrix multiplication is a mathematical operation that combines two matrices to produce a third matrix. This operation is only possible when the number of columns in the first matrix equals the number of rows in the second matrix. If matrix A has dimensions m×n and matrix B has dimensions n×p, the resulting matrix C will have dimensions m×p. Matrix Multiplication Rule Matrix A m × n 2 × 3 × Matrix B n × p ...

Read More

Decimal.Negate() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 773 Views

The Decimal.Negate() method in C# is used to return the result of multiplying the specified decimal value by negative one. This method effectively changes the sign of a decimal number − positive numbers become negative and negative numbers become positive. Syntax Following is the syntax − public static decimal Negate(decimal val); Parameters val − The decimal value to negate. Return Value Returns a decimal number that is equal to val multiplied by negative one (-1). If val is positive, the result is negative. If val is negative, the result ...

Read More

What are dynamic data types in C#?

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

The dynamic data type in C# allows you to store any type of value in a variable. Unlike other data types, type checking for dynamic variables occurs at runtime rather than compile-time, providing flexibility but requiring careful handling to avoid runtime errors. Syntax Following is the syntax for declaring a dynamic variable − dynamic = value; Basic Dynamic Variable Declaration Example using System; class Program { public static void Main() { dynamic val1 = 100; ...

Read More
Showing 10701–10710 of 61,297 articles
Advertisements