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
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
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
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
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
A cuboid is a three-dimensional geometric shape with six rectangular faces, where opposite faces are equal in dimensions. It has three dimensions: length, breadth (width), and height. We can calculate the volume, perimeter, and surface area of a cuboid using specific mathematical formulas. Cuboid Structure Length Breadth Height Formulas The following formulas are ... Read More
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
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
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
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance