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
Articles by Nizamuddin Siddiqui
Page 3 of 196
How to convert string to title case in C#?
Title case is any text, such as in a title or heading, where the first letter of major words is capitalized. Title case or headline case is a style of capitalization used for rendering the titles of published works or works of art in English. When using title case, all words are capitalized except for minor words (like articles, prepositions, and conjunctions) unless they are the first or last word of the title. C# provides the ToTitleCase method through the TextInfo class to convert strings to title case format. This method capitalizes the first letter of each word while ...
Read MoreHow to check whether the tree is symmetric or not using iterative in C#?
A symmetric binary tree is one where the left subtree is a mirror reflection of the right subtree. In the iterative approach, we use two queues to traverse both subtrees simultaneously and compare their values in mirror positions. The algorithm works by enqueueing nodes from the left and right subtrees in opposite orders. For the left subtree, we add left child first, then right child. For the right subtree, we add right child first, then left child. This ensures we compare mirror positions correctly. Syntax Following is the basic structure for checking tree symmetry iteratively − ...
Read MoreHow to use String Format to show decimal up to 2 places or simple integer in C#?
The String.Format method in C# converts values to formatted strings and inserts them into another string. It's particularly useful for displaying numbers with consistent decimal places, showing integers as decimals when needed, or keeping integers without unnecessary decimal points. Syntax Following is the syntax for String.Format with decimal formatting − string.Format("{0:format}", value) Common decimal format specifiers − "{0:0.00}" // Always shows 2 decimal places "{0:F2}" // Fixed-point with 2 decimal places "{0:N2}" // Number format with 2 decimal places ...
Read MoreHow to check whether the tree is symmetric or not using recursion in C#?
A symmetric binary tree is a tree where the left subtree is a mirror image of the right subtree. In C#, we can check if a tree is symmetric using recursion by comparing corresponding nodes from left and right subtrees. The recursive approach works by first checking if the tree is null (which is symmetric by definition), then calling a helper method to compare the left and right subtrees as mirror images of each other. Algorithm Steps If the root is null, the tree is symmetric Compare left subtree with right subtree using a mirror comparison ...
Read MoreHow to invert a binary search tree using recursion in C#?
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 MoreHow to check whether a binary tree is a valid binary search tree using recursion in C#?
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 MoreHow to check whether a binary tree has the given path sum in C#?
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 MoreWhat is the difference between Static class and Singleton instance in C#?
A static class is declared using the static keyword and contains only static members that belong to the class itself rather than any instance. A Singleton is a design pattern that ensures only one instance of a class can be created and provides global access to that instance. Static Class A static class cannot be instantiated and all its members must be static. It is loaded automatically by the .NET Framework before the class is referenced for the first time − Syntax public static class ClassName { public static void Method() ...
Read MoreHow to implement a Singleton design pattern in C#?
The Singleton design pattern belongs to the Creational type pattern. It ensures that only one instance of a particular class is created throughout the application lifecycle. This single instance coordinates actions across the application and provides global access to shared resources. The Singleton pattern is useful when you need exactly one instance of a class, such as for logging, caching, thread pools, or configuration settings. Implementation Guidelines Declare all constructors as private to prevent external instantiation. Provide a static property or method that returns the single instance. Store the instance in a static field to ensure ...
Read MoreWhat is typeof, GetType or is in C#?
C# provides three important operators for working with types: typeof, GetType(), and is. These operators allow you to examine object types at runtime, perform type checking, and enable reflection-based operations. Syntax Following is the syntax for the typeof operator − Type type = typeof(ClassName); Following is the syntax for the GetType() method − Type type = objectInstance.GetType(); Following is the syntax for the is operator − bool result = objectInstance is TargetType; Understanding typeof, GetType, and is Type Operations in C# ...
Read More