Programming Articles

Page 804 of 2547

Optimization Tips for C# Code

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 909 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 460 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 620 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 307 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 476 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 771 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 654 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

Private Variables in C#

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

The private access specifier in C# allows a class to hide its member variables and member functions from other functions and objects. Only methods of the same class can access its private members. Even an instance of a class cannot access its private members directly from outside the class. Syntax Following is the syntax for declaring a private variable − private dataType variableName; For example − private double length; private int count; private string name; Key Rules of Private Variables Private members can only be accessed within ...

Read More

How to check if String is Palindrome using C#?

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

A palindrome is a string that reads the same forwards and backwards, such as "Level", "madam", or "racecar". In C#, there are several ways to check if a string is a palindrome. Using Array.Reverse() Method The simplest approach is to reverse the string and compare it with the original. First, convert the string to a character array − char[] ch = str.ToCharArray(); Then reverse the array using Array.Reverse() − Array.Reverse(ch); Finally, compare the reversed string with the original using case-insensitive comparison − bool res = str.Equals(rev, StringComparison.OrdinalIgnoreCase); ...

Read More
Showing 8031–8040 of 25,466 articles
« Prev 1 802 803 804 805 806 2547 Next »
Advertisements