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
Server Side Programming Articles
Page 757 of 2109
Assertions in C#
Assertions in C# are debugging tools used to check assumptions in your code during development. They have two main arguments − a boolean expression that should evaluate to true, and an optional message to display if the assertion fails. Assertions are particularly useful in large and complex programs to quickly identify logic errors that may arise when code is modified. They help catch bugs early in the development process. Syntax Following is the syntax for using Debug.Assert() − Debug.Assert(condition); Debug.Assert(condition, "Error message"); Debug.Assert(condition, "Error message", "Detailed message"); Key Rules Assertions ...
Read MoreAre arrays zero indexed in C#?
Yes, arrays are zero-indexed in C#. This means the first element of an array is stored at index 0, the second element at index 1, and so on. The relationship between array length and indexing follows a consistent pattern. Array Length vs Index Range If the array is empty, it has zero elements and length 0. If the array has one element at index 0, then it has length 1. If the array has two elements at indexes 0 and 1, then it has length 2. If the array has ...
Read MoreAddition 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 More