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 on Trending Technologies
Technical articles with clear explanations and examples
How to implement coin change problem using bottom-up approach using C#?
The coin change problem is a classic dynamic programming challenge where we need to find the minimum number of coins required to make a given amount. The bottom-up approach builds solutions incrementally, starting from the smallest amounts and working up to the target amount. This approach uses dynamic programming to avoid recalculating the same subproblems multiple times, storing previously computed results in an array. Time complexity − O(n × t) where n is the amount and t is the number of coin types Space complexity − O(n) for the dynamic programming array Syntax Following is the ...
Read MoreCheck if two String objects have the same value in C#
To check if two String objects have the same value in C#, you can use several methods. The most common approach is using the Equals() method, which performs a case-sensitive comparison of string values. Syntax Following are the main syntax forms for comparing string values − string1.Equals(string2) string.Equals(string1, string2) string1 == string2 Using the Equals() Method The Equals() method is the recommended way to compare string values. It returns true if both strings have identical content − Example using System; public class Demo { public ...
Read MoreCopy StringCollection at the specified index of array in C#
The StringCollection.CopyTo() method in C# copies all elements from a StringCollection to a compatible array starting at the specified index. This method is particularly useful when you need to transfer string data from a collection to an array for further processing. Syntax Following is the syntax for the CopyTo() method − public void CopyTo(string[] array, int index) Parameters array − The one-dimensional array that is the destination of the elements copied from StringCollection. index − The zero-based index in the destination array at which copying begins. ...
Read MoreHow 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 MoreCheck if two StringBuilder objects are Equal in C#
To check if two StringBuilder objects are equal in C#, you need to understand that StringBuilder.Equals() checks for reference equality, not content equality. For content comparison, you must convert the StringBuilder objects to strings first. Syntax Following is the syntax for checking StringBuilder equality − // Reference equality bool isEqual = stringBuilder1.Equals(stringBuilder2); // Content equality bool isContentEqual = stringBuilder1.ToString().Equals(stringBuilder2.ToString()); Using Reference Equality The Equals() method on StringBuilder checks if both objects reference the same instance − using System; using System.Text; public class Demo { public static ...
Read MoreCopy StringDictionary to Array at the specified index in C#
The StringDictionary class in C# provides the CopyTo() method to copy its key-value pairs to a DictionaryEntry array starting at a specified index. This method is useful when you need to convert dictionary data into an array format for processing or manipulation. Syntax The syntax for copying a StringDictionary to an array at a specified index is − stringDictionary.CopyTo(array, index); Parameters array − The destination DictionaryEntry[] array where elements will be copied. index − The zero-based index in the array where copying begins. Using CopyTo() Starting at Index 0 ...
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 MoreC# Program to Find out the value of Sin(x)
In this article, we will learn how to create a C# program to find the value of Sin(x). The sine function is a fundamental trigonometric function that calculates the ratio of the opposite side to the hypotenuse in a right triangle. C# provides built-in methods to calculate sine values, and we can also implement our own calculation using mathematical series. Syntax C# provides a built-in method in the Math class to calculate sine values − Math.Sin(double angleInRadians) The Maclaurin series expansion for sin(x) is − sin(x) = x - x³/3! + x⁵/5! ...
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 More