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
Articles on Trending Technologies
Technical articles with clear explanations and examples
Compound assignment operators in C#
Compound assignment operators in C# provide a shorter syntax to perform an operation and assign the result back to the same variable. These operators combine arithmetic, bitwise, or shift operations with assignment in a single step. For example, x += 5 is equivalent to x = x + 5, but more concise and readable. Syntax The general syntax for compound assignment operators is − variable operator= value; This is equivalent to − variable = variable operator value; Types of Compound Assignment Operators Operator Name Equivalent ...
Read MoreC# program to print all sublists of a list
A sublist (or subsequence) of a string contains characters from the original string in the same order, but not necessarily consecutive. For example, from the string "xyz", possible sublists include "x", "xy", "xz", "y", "yz", "z", and "xyz". This program generates all possible sublists of a given string by building them incrementally using nested loops and dynamic list operations. How the Algorithm Works The algorithm processes each character of the input string and creates new sublists by combining existing sublists with the current character. It maintains a list that grows with each iteration, containing all possible sublists ...
Read MoreLarge Fibonacci Numbers in C#
To display large Fibonacci numbers in C#, we need to handle numbers that exceed the range of standard integer types. The Fibonacci sequence grows exponentially, so after just 40-50 terms, the values become too large for int or even long data types. For truly large Fibonacci numbers, we use the BigInteger class from System.Numerics, which can handle arbitrarily large integers without overflow. Syntax Following is the basic syntax for generating Fibonacci numbers − int val1 = 0, val2 = 1, val3; for (int i = 2; i < n; i++) { val3 ...
Read MoreHow to print the contents of array horizontally using C#?
Printing array contents horizontally in C# means displaying all elements in a single line, separated by spaces or other delimiters. This is useful for creating formatted output where elements appear side by side rather than vertically. When you print an array using a regular loop with Console.WriteLine(), each element appears on a new line. To display elements horizontally, C# provides several approaches. Syntax Using string.Join() method − string.Join(separator, array) Using Console.Write() in a loop − for (int i = 0; i < array.Length; i++) { Console.Write(array[i] + ...
Read MoreConstructor Overloading in C#
Constructor overloading in C# allows you to define multiple constructors within the same class, each with different parameters. This provides flexibility in object initialization, allowing different ways to create instances of the same class. Constructor overloading follows the same rules as method overloading − constructors must have different parameter lists (number, type, or order of parameters). Syntax Following is the syntax for constructor overloading − public class ClassName { public ClassName() { // default constructor } ...
Read MoreHow to check if a C# list is empty?
In C#, there are several ways to check if a List is empty. The most common approaches include using the Count property, the Any() LINQ method, or comparing against an empty collection. Syntax Following are the common syntaxes for checking if a list is empty − // Using Count property if (list.Count == 0) { } // Using Any() method if (!list.Any()) { } // Using Count with comparison if (list.Count > 0) { } Using Count Property The Count property returns the number of elements in the list. When Count ...
Read MoreHow to access elements from an array in C#?
Arrays in C# are collections of elements that can be accessed using an index. Array indexing starts from 0, meaning the first element is at index 0, the second at index 1, and so on. Syntax Following is the syntax for accessing array elements by index − arrayName[index] Following is the syntax for declaring and initializing an array − dataType[] arrayName = new dataType[size] {element1, element2, element3}; Using Index to Access Elements Each element in an array has a specific position called an index. You can access any element ...
Read MoreGlobal and Local Variables in C#
In C#, variables are classified by their scope − the region of code where they can be accessed. The two main types are local variables (declared within methods) and global variables (which C# handles through static class members and namespace aliases). Local Variables A local variable is declared within a method, constructor, or block of code. Its scope is limited to that specific block, meaning it can only be accessed within the method or block where it was declared. Syntax dataType variableName; // or dataType variableName = value; Example using System; ...
Read MorePath methods in C#
To handle File Paths in C#, use the Path methods. These methods come under the System.IO namespace and provide a reliable way to work with file and directory paths across different operating systems. The Path class contains static methods that perform common operations on strings that contain file or directory path information. These methods handle path separators, invalid characters, and other platform-specific details automatically. Syntax Following is the syntax for commonly used Path methods − string extension = Path.GetExtension(path); string fileName = Path.GetFileName(path); string fileNameWithoutExt = Path.GetFileNameWithoutExtension(path); string directoryName = Path.GetDirectoryName(path); string fullPath = Path.GetFullPath(path); ...
Read MoreConstructors in C#
A constructor in C# is a special method that gets invoked automatically when an object is created. The constructor has the same name as the class and is used to initialize the object's state. Constructors do not have a return type, not even void. Syntax Following is the basic syntax for declaring a constructor − public class ClassName { public ClassName() { // constructor body } } Types of Constructors C# supports several types of constructors − Default ...
Read More