Csharp Articles

Page 94 of 196

What is garbage collection in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 9K+ Views

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 More

How to write multi-line comments in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 949 Views

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 More

C# program to print all the numbers divisible by 3 and 5 for a given number

Samual Sam
Samual Sam
Updated on 17-Mar-2026 6K+ Views

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 More

How to assign same value to multiple variables in single statement in C#?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 3K+ Views

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 More

C# program to print all sublists of a list

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 754 Views

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 More

How to check if a C# list is empty?

George John
George John
Updated on 17-Mar-2026 3K+ Views

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 More

IS vs AS Operators in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 1K+ Views

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 More

static keyword in C#

George John
George John
Updated on 17-Mar-2026 3K+ Views

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 More

Ternary Operator in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 3K+ Views

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 More

Push vs pop in stack class in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 747 Views

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
Showing 931–940 of 1,951 articles
« Prev 1 92 93 94 95 96 196 Next »
Advertisements