The Stack class in C# represents a last-in, first-out (LIFO) collection of objects. It is used when you need to store and retrieve elements in reverse order — the last element added is the first one to be removed. The Stack class provides two fundamental operations: Push() to add elements and Pop() to remove elements from the top of the stack. Stack LIFO Operations D (Top) C B A ... Read More
Converting a decimal number to binary using recursion in C# involves repeatedly dividing the number by 2 and collecting the remainders. The recursive approach breaks down the problem into smaller subproblems until the base case is reached. Syntax Following is the basic syntax for the recursive binary conversion method − public void ConvertToBinary(int decimalNumber) { if (decimalNumber > 0) { ConvertToBinary(decimalNumber / 2); Console.Write(decimalNumber % 2); } } How It ... Read More
The + operator is used to concatenate two or more string objects in C#. This operator provides a simple and intuitive way to combine strings, making it one of the most commonly used string operations in C# programming. Syntax Following is the basic syntax for string concatenation using the + operator − string result = string1 + string2; string result = string1 + string2 + string3; Using + Operator for String Concatenation Example 1: Basic String Concatenation using System; class Program { static void Main() { ... Read More
C is a general-purpose, high-level programming language originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was first implemented on the DEC PDP-11 computer in 1972. C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg. It was designed to combine the power of C++ with the simplicity of Visual Basic. While both languages share the letter "C" in their names, they represent different programming paradigms and approaches. Here are the key differences between C and C#. ... Read More
Comparing two lists for equality in C# can be done using several approaches. The most common methods include using SequenceEqual() for order-dependent comparison, Except() to find differences, and custom logic for specific comparison requirements. Using SequenceEqual() for Order-Dependent Comparison The SequenceEqual() method from LINQ compares two sequences element by element in the same order − using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List list1 = new List {"A", "B", "C"}; List list2 ... Read More
In C#, you can remove empty strings from a list using several methods. Empty strings can be truly empty ("") or contain only whitespace characters (" "). This article demonstrates different approaches to remove these empty or whitespace-only strings from a list. Syntax Using RemoveAll() method to remove empty strings − list.RemoveAll(string.IsNullOrEmpty); Using RemoveAll() with lambda expression to remove empty and whitespace strings − list.RemoveAll(x => string.IsNullOrWhiteSpace(x)); Using LINQ Where() method to filter out empty strings − var filteredList = list.Where(x => !string.IsNullOrEmpty(x)).ToList(); Using RemoveAll() Method ... Read More
Finding missing numbers in a sequence is a common programming problem. In C#, you can solve this efficiently using LINQ operations by comparing the original sequence with a complete range of numbers. Using LINQ Except Method The most straightforward approach is to create a complete range from the minimum to maximum value and use the Except method to find missing numbers − using System; using System.Collections.Generic; using System.Linq; public class Program { public static void Main() { List myList = new List(){1, 2, 3, 5, 8, ... Read More
The division operator (/) in C# is used to divide one number by another. It performs mathematical division between a numerator and denominator, such as 9 / 3 = 3. The division operator is part of the arithmetic operators in C# and behaves differently depending on the data types involved. Understanding these differences is crucial for accurate calculations. Syntax Following is the syntax for the division operator − result = numerator / denominator; Integer Division When both operands are integers, C# performs integer division, which truncates the decimal part and returns only ... Read More
To convert a decimal number to its octal equivalent in C#, we use the division method where we repeatedly divide the decimal number by 8 and collect the remainders. The octal number system uses base 8, meaning it only uses digits 0-7. How It Works The conversion process involves dividing the decimal number by 8 repeatedly and storing the remainders in reverse order. Each remainder represents a digit in the octal representation. Decimal to Octal Conversion Process 18 ÷ 8 = ... Read More
The Pythagorean theorem states that in a right-angled triangle, the square of the hypotenuse (the side opposite the right angle) is equal to the sum of the squares of the other two sides. In C#, we can use the Math.Sqrt() method to calculate the hypotenuse or find missing sides. Syntax The basic formula for Pythagorean theorem is − c² = a² + b² c = Math.Sqrt(a * a + b * b) Where c is the hypotenuse, and a and b are the other two sides of the right triangle. ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance