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 94 of 196
What is garbage collection in C#?
The garbage collector (GC) in C# is an automatic memory management system that handles the allocation and release of memory for managed objects. It eliminates the need for manual memory management, preventing memory leaks and reducing programming errors. The garbage collector operates on the managed heap, where all reference type objects are stored. When objects are no longer referenced by the application, the GC automatically reclaims their memory space. How Garbage Collection Works Garbage Collection Process Object Created Memory Low ...
Read MoreHow to write multi-line comments in C#?
Multi-line comments in C# are comments that span more than one line. They are useful for adding detailed explanations, documenting code blocks, or temporarily disabling large sections of code during development. Syntax Multi-line comments in C# use the following syntax − /* This is a multi-line comment that can span multiple lines All text between /* and */ is ignored */ The compiler ignores everything between /* and */, making it perfect for lengthy explanations or code documentation. Basic Multi-line Comment Example using System; ...
Read MoreC# program to print all the numbers divisible by 3 and 5 for a given number
To print numbers divisible by both 3 and 5, we use the modulus operator % with the logical AND operator &&. A number is divisible by both 3 and 5 if the remainder is zero when divided by each of these numbers. Syntax Following is the syntax to check if a number is divisible by both 3 and 5 − if (num % 3 == 0 && num % 5 == 0) { // number is divisible by both 3 and 5 } Alternatively, since a number divisible by both 3 ...
Read MoreHow to assign same value to multiple variables in single statement in C#?
In C#, you can assign the same value to multiple variables in a single statement using the assignment operator. This technique is called chained assignment and works because the assignment operator returns the assigned value. Syntax Following is the syntax for assigning the same value to multiple variables − variable1 = variable2 = variable3 = value; The assignment is evaluated from right to left, so value is first assigned to variable3, then that result is assigned to variable2, and finally to variable1. How It Works The assignment operator (=) in C# returns ...
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 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 MoreIS vs AS Operators in C#
The is and as operators in C# are used for type checking and type conversion. The is operator checks if an object is compatible with a given type and returns a boolean value, while the as operator attempts to convert an object to a specified type and returns null if the conversion fails. Syntax Following is the syntax for the is operator − expr is type Following is the syntax for the as operator − expr as type Where expr is the expression to test and type is the target ...
Read Morestatic keyword in C#
The static keyword in C# is used to declare class members that belong to the class itself rather than to any specific instance. When a member is declared as static, it means there is only one copy of that member shared across all instances of the class. Static members can be accessed directly using the class name without creating an object instance. They are commonly used for utility methods, constants, and shared data that should be consistent across all instances of a class. Syntax Following is the syntax for declaring static members − public static ...
Read MoreTernary Operator in C#
The ternary operator in C# is a conditional operator that provides a concise way to evaluate expressions based on a Boolean condition. It takes three operands and returns one of two values depending on whether the condition is true or false. The ternary operator is also known as the conditional operator and uses the syntax condition ? value_if_true : value_if_false. It's particularly useful for simple conditional assignments and can make code more readable when used appropriately. Syntax Following is the syntax for the ternary operator − result = condition ? value_if_true : value_if_false; ...
Read MorePush vs pop in stack class in C#
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