Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Csharp Articles
Page 81 of 196
Addition and Concatenation in C#
In C#, addition refers to mathematical operations with numeric types, while concatenation refers to joining strings together. The + operator can perform both operations depending on the operand types, and C# provides several methods for string concatenation. Syntax Following is the syntax for numeric addition − int result = number1 + number2; Following is the syntax for string concatenation using the + operator − string result = string1 + string2; Following is the syntax for string concatenation using String.Concat() method − string result = String.Concat(string1, string2); ...
Read MoreAbstract vs Sealed Classes vs Class Members in C#
The abstract class includes abstract and non-abstract methods. You cannot instantiate an abstract class directly. The sealed class prevents inheritance and you cannot use it as a base class. Both abstract and sealed classes can contain various types of class members with different access modifiers and behaviors. Abstract Classes To declare an abstract class, you need to place the keyword abstract before the class definition. An abstract class can contain abstract methods that must be implemented by derived classes − Syntax public abstract class ClassName { public abstract void MethodName(); ...
Read MoreThree Different ways to calculate factorial in C#
The factorial of a number is the product of all positive integers less than or equal to that number. For example, factorial of 5 (written as 5!) is 5 × 4 × 3 × 2 × 1 = 120. In C#, you can calculate factorial using three different approaches − Syntax The mathematical definition of factorial is − n! = n × (n-1) × (n-2) × ... × 2 × 1 0! = 1 (by definition) 1! = 1 Factorial Calculation Methods For Loop ...
Read MoreBoxing and Unboxing in C#
Boxing is the process of converting a value type to a reference type by wrapping it in an object. Unboxing is the reverse process — extracting the value type from the boxed object. These operations allow value types to be treated as objects when needed. Boxing and Unboxing Process Value Type int myVal = 12 Reference Type object myBoxed Boxing (Implicit) Unboxing (Explicit Cast) Stored on Stack ...
Read MoreBackground and foreground thread in C#
A thread is defined as the execution path of a program. Each thread defines a unique flow of control. In C#, threads are classified as either foreground threads or background threads based on their behavior when the main application terminates. The key difference is that foreground threads keep the application alive, while background threads are automatically terminated when all foreground threads finish execution. Thread Types Comparison Foreground Thread Background Thread Keeps the application running until it completes Terminated automatically when all foreground threads end Default thread type (IsBackground ...
Read MoreBigInteger Class in C#
The BigInteger class in C# is designed to handle arbitrarily large integers that exceed the limits of standard integer types. It is part of the System.Numerics namespace and provides support for mathematical operations on very large numbers without overflow. Unlike built-in integer types like int or long, BigInteger can represent integers of any size, limited only by available memory. This makes it ideal for cryptographic calculations, mathematical computations, and scenarios requiring precise arithmetic with large numbers. Syntax The BigInteger structure declaration − [SerializableAttribute] public struct BigInteger : IFormattable, IComparable, IComparable, IEquatable Creating a ...
Read MoreBinary to decimal using C#
Converting binary numbers to decimal is a fundamental operation in programming. In C#, you can convert binary to decimal using manual calculation methods or built-in functions. The binary number system uses base 2, where each digit position represents a power of 2. How Binary to Decimal Conversion Works Binary to decimal conversion follows a simple mathematical principle. Each binary digit (bit) is multiplied by the corresponding power of 2, starting from 2⁰ for the rightmost digit − Binary 1010 → Decimal 10 1 ...
Read MoreBitwise right shift operators in C#
The bitwise right shift operator (>>) in C# moves the bits of the left operand to the right by the number of positions specified by the right operand. This operation effectively divides the number by powers of 2. Syntax Following is the syntax for the bitwise right shift operator − result = operand >> numberOfPositions; How It Works When you right shift a binary number, each bit moves to the right by the specified number of positions. Vacant positions on the left are filled with zeros for positive numbers and ones for negative ...
Read MoreC# program to check if binary representation is palindrome
A binary palindrome is a number whose binary representation reads the same forwards and backwards. To check if a number's binary representation is a palindrome, we need to reverse its binary form and compare it with the original. For example, the number 5 has binary representation 101, which reads the same forwards and backwards, making it a binary palindrome. How It Works The algorithm uses bitwise operations to reverse the binary representation − Left shift (=) moves bits to the right, effectively dividing by 2 AND operation (&) checks if the least ...
Read MoreC# program to check if there are K consecutive 1's in a binary number
A C# program to check if there are K consecutive 1's in a binary number involves counting the longest sequence of consecutive 1's and comparing it with the required count K. This is useful for binary pattern analysis and digital signal processing applications. Approach The algorithm iterates through the binary array, maintaining a counter for consecutive 1's. When a 0 is encountered, the counter resets. The maximum consecutive count is tracked using Math.Max() method. Using Boolean Array Representation A binary number can be represented as a boolean array where true represents 1 and false represents 0 ...
Read More