Programming Articles

Page 802 of 2547

Iterators in C#

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

An iterator in C# performs custom iteration over a collection using the yield keyword. It returns elements one at a time and remembers its current position, making it memory-efficient for large datasets. Iterators implement lazy evaluation, meaning values are generated only when requested. Syntax Following is the syntax for creating an iterator method − public static IEnumerable MethodName() { // logic here yield return value; // more logic yield return anotherValue; } The yield break statement can be ...

Read More

What are generic delegates in C#?

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

Generic delegates in C# allow you to create delegate types with type parameters, providing flexibility to work with different data types without defining separate delegate declarations for each type. The .NET Framework provides several built-in generic delegates in the System namespace that eliminate the need for custom delegate definitions in most scenarios. Syntax Following is the syntax for declaring a custom generic delegate − delegate TResult DelegateName(T parameter); Built-in generic delegates use these syntaxes − Action actionDelegate = method; // void return type Func funcDelegate = method; // ...

Read More

Private Constructors and Singleton Classes in C#

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

A private constructor is a constructor that cannot be called from outside the class. It is primarily used in classes containing only static members or to implement the Singleton design pattern, which ensures that only one instance of a class can exist throughout the application's lifetime. Syntax Following is the syntax for declaring a private constructor − class ClassName { private ClassName() { // private constructor body } } Private Constructor for Static-Only Classes When a class contains only static members, ...

Read More

Clear a list in C#

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

To clear a list in C#, you use the Clear() method which removes all elements from the list. This method is part of the List class and provides an efficient way to empty a list without recreating it. Syntax Following is the syntax for the Clear()

Read More

C# Program to remove a node at the end of the Linked List

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

In C#, you can remove the last node from a LinkedList using the RemoveLast() method. This method removes and returns the last node in the linked list, making it an efficient way to delete the tail element. Syntax Following is the syntax for removing the last node from a LinkedList − linkedList.RemoveLast(); The RemoveLast() method removes the last node and has no return value. If the list is empty, it throws an InvalidOperationException. How It Works The LinkedList class maintains references to both the first and last nodes. When RemoveLast() is called, ...

Read More

C# program to perform Quick sort using Recursion

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

Quick Sort is a highly efficient sorting algorithm that uses the divide and conquer approach. It selects a pivot element from the array and partitions the other elements into two sub-arrays according to whether they are less than or greater than the pivot. The sub-arrays are then recursively sorted. The algorithm works by placing the pivot in its correct position and then recursively applying the same process to the left and right sub-arrays until the entire array is sorted. How Quick Sort Works Quick Sort Process Initial Array: ...

Read More

Boolean.CompareTo(Boolean) Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 671 Views

The Boolean.CompareTo(Boolean) method in C# is used to compare the current Boolean instance with another Boolean object and returns an integer indicating their relative values. Syntax Following is the syntax − public int CompareTo(bool value); Parameters value − A Boolean object to compare with the current instance. Return Value The method returns an integer value − -1 − if the current instance is false and value is true 0 − if the current instance and value are equal 1 − if the current instance ...

Read More

How to write the first program in C#?

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

Writing your first program in C# is the foundation of learning this powerful programming language. A C# program consists of several key components that work together to produce output. Let's explore the structure and elements of a basic C# program. Syntax Following is the basic structure of a C# program − using System; namespace NamespaceName { class ClassName { static void Main(string[] args) { // Program logic here ...

Read More

What are key-based I/O collections in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 267 Views

Key-based I/O collections in C# are collections that store data as key-value pairs, where you can access values using their associated keys. The primary example of this is the SortedList class, which maintains elements in sorted order based on the keys. Syntax Following is the syntax for declaring a generic SortedList − SortedList listName = new SortedList(); Following is the syntax for adding key-value pairs − listName.Add(key, value); listName[key] = value; // alternative syntax Key Features of SortedList Stores key-value pairs sorted by keys in ascending order ...

Read More

What is unmanaged code in C#?

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

Unmanaged code in C# refers to code that executes outside the control of the .NET Common Language Runtime (CLR). This type of code is also known as unsafe code because it bypasses many of the safety mechanisms that make C# a managed language. In C#, unmanaged code typically involves the use of pointers and direct memory manipulation, similar to languages like C and C++. To use unmanaged code, you must explicitly mark code blocks with the unsafe keyword. Key Characteristics of Unmanaged Code Applications that are not under the control of the CLR are unmanaged. ...

Read More
Showing 8011–8020 of 25,466 articles
« Prev 1 800 801 802 803 804 2547 Next »
Advertisements