Programming Articles

Page 700 of 2547

C# Program to find the greatest number in an array using the WHERE clause LINQ

Ankit kumar
Ankit kumar
Updated on 17-Mar-2026 423 Views

In this article, we will find the greatest number in an array using the WHERE clause in LINQ. LINQ (Language Integrated Query) provides a unified way to query data from different sources in C#, making code more readable and concise with built-in filtering, sorting, and grouping capabilities. Language Integrated Query (LINQ) LINQ is a component of the .NET framework that allows type-safe data access from various sources like databases, XML documents, and collections. It uses clauses to perform different operations on data − From Clause − Specifies the data source and range variable. Where Clause − ...

Read More

How to invert a binary search tree using recursion in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 2K+ Views

To invert a binary search tree, we swap the left and right child nodes for every node in the tree recursively. This operation creates a mirror image of the original tree. The algorithm uses a recursive approach where we process each node by first inverting its left and right subtrees, then swapping their positions. The process involves calling a method InvertBinaryTree that takes a node as a parameter. If the node is null, we return null. Otherwise, we recursively call the method on both left and right children, then swap the left and right child references. ...

Read More

Get a read-only copy of the OrderedDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 214 Views

The OrderedDictionary class in C# provides the AsReadOnly() method to create a read-only copy of the collection. This wrapper prevents any modifications to the dictionary while maintaining access to all elements in their insertion order. Syntax Following is the syntax for creating a read-only copy of an OrderedDictionary − OrderedDictionary readOnlyDict = originalDict.AsReadOnly(); Return Value The AsReadOnly() method returns an OrderedDictionary wrapper that is read-only. Any attempt to modify this wrapper will throw a NotSupportedException. Using AsReadOnly() Method The following example demonstrates how to create a read-only copy and verify its ...

Read More

Copy the entire LinkedList to Array in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 420 Views

The LinkedList class in C# provides the CopyTo() method to copy all elements from a LinkedList to an array. This method is useful when you need to convert a dynamic LinkedList structure into a fixed-size array for processing or storage. Syntax Following is the syntax for copying a LinkedList to an array − linkedList.CopyTo(array, arrayIndex); Parameters array − The one-dimensional array that is the destination of elements copied from LinkedList. arrayIndex − The zero-based index in array at which copying begins. LinkedList ...

Read More

How to check whether a binary tree is a valid binary search tree using recursion in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 517 Views

A Binary Search Tree (BST) is a tree structure where each node's left child contains values smaller than the node, and the right child contains values greater than the node. To validate whether a binary tree is a valid BST using recursion, we need to check that each node's value falls within its allowed range based on its position in the tree. The recursive approach uses upper and lower bounds that get updated as we traverse the tree. For each node, we verify that its value lies within the current bounds, then recursively check the left subtree with updated ...

Read More

Remove all elements from a HashSet in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 274 Views

To remove all elements from a HashSet in C#, you use the Clear() method. This method removes all elements from the HashSet and resets its count to zero. The Clear() method is the most efficient way to empty a HashSet completely. Syntax Following is the syntax for the Clear() method − hashSet.Clear(); Parameters The Clear() method takes no parameters. Return Value The Clear() method returns void (no return value). Using Clear() Method Example using System; using System.Collections.Generic; public class Demo { public static ...

Read More

C# Program to Generate Marksheet of Student

Ankit kumar
Ankit kumar
Updated on 17-Mar-2026 4K+ Views

A marksheet generation program is a practical application that calculates a student's total marks, percentage, and grade based on subject scores. This C# program demonstrates how to create a simple marksheet system using basic input/output operations, arithmetic calculations, and conditional logic. Algorithm The marksheet generation follows these steps − Step 1 − Declare variables for student roll number, name, subject marks, total marks, and percentage. Step 2 − Accept input for student details and marks in each subject. Step 3 − Calculate total marks by summing all subject marks. Step 4 − Calculate percentage ...

Read More

How to check whether a binary tree has the given path sum in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 380 Views

A binary tree has a path sum when there exists a root-to-leaf path where the sum of all node values equals a given target sum. The HasPathSum method recursively traverses the tree, subtracting each node's value from the target sum until reaching a leaf node. Syntax Following is the syntax for checking path sum in a binary tree − public bool HasPathSum(Node node, int targetSum) { if (node == null) return false; if (node.LeftChild == null && node.RightChild == null) { ...

Read More

Remove all elements from a SortedList in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 219 Views

To remove all elements from a SortedList in C#, you use the Clear() method. This method removes all key-value pairs from the SortedList and sets the Count property to zero. Syntax Following is the syntax for the Clear() method − sortedList.Clear(); Parameters The Clear() method does not take any parameters. Return Value The Clear() method does not return any value. It has a return type of void. SortedList.Clear() Operation Before Clear() {A:1, B:2, C:3} Count = 3 ...

Read More

Copying BitArray elements to an Array in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 328 Views

The BitArray class in C# provides the CopyTo() method to copy its elements to a compatible one-dimensional array. This method is useful when you need to transfer bit values from a BitArray to a regular array for further processing or storage. Syntax Following is the syntax for copying BitArray elements to an array − bitArray.CopyTo(array, arrayIndex); Parameters array − The target one-dimensional array to copy elements to. Must be compatible with BitArray elements (bool[], int[], or byte[]). arrayIndex − The zero-based index in the target array at which copying begins. ...

Read More
Showing 6991–7000 of 25,466 articles
« Prev 1 698 699 700 701 702 2547 Next »
Advertisements