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 print duplicate characters in a String using C#?
Finding duplicate characters in a string is a common programming task in C#. A duplicate character is one that appears more than once in the string. We can solve this by counting the frequency of each character and then displaying those with a count greater than 1. Using Character Frequency Array The most efficient approach uses an integer array to store the frequency of each character. Since there are 256 possible ASCII characters, we create an array of size 256 − using System; class Demo { static int maxCHARS = 256; ...
Read MoreHow to generate a string randomly using C#?
Generating random strings in C# is useful for creating passwords, test data, or unique identifiers. There are several approaches to generate random strings, from simple character-based methods to more advanced techniques using predefined character sets. Syntax Following is the basic syntax for generating random strings using Random class − Random random = new Random(); char randomChar = (char)random.Next(startValue, endValue); Following is the syntax using a character array − char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); char randomChar = chars[random.Next(chars.Length)]; Using ASCII Values for Random String Generation This method generates random characters by ...
Read MoreDifferent Methods to find Prime Numbers in C#
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. In C#, there are several methods to check if a number is prime, each with different approaches and efficiency levels. What is a Prime Number? A prime number is divisible only by 1 and itself. For example, 2, 3, 5, 7, 11 are prime numbers. The number 1 is not considered prime, and 2 is the only even prime number. Prime vs Composite Numbers Prime Numbers ...
Read MoreConvert.ToSByte(String, IFormatProvider) Method in C#
The Convert.ToSByte(String, IFormatProvider) method in C# converts the specified string representation of a number to an equivalent 8-bit signed integer, using the specified culture-specific formatting information. This method is particularly useful when working with numeric strings that may have different formatting conventions based on locale. Syntax Following is the syntax − public static sbyte ToSByte(string value, IFormatProvider provider); Parameters value − A string that contains the number to convert. The value must be between -128 and 127. provider − An object that supplies culture-specific formatting information. This can be ...
Read MoreTernary Operator in C#
The ternary operator in C# is a conditional operator that provides a concise way to evaluate expressions based on a Boolean condition. It takes three operands and returns one of two values depending on whether the condition is true or false. The ternary operator is also known as the conditional operator and uses the syntax condition ? value_if_true : value_if_false. It's particularly useful for simple conditional assignments and can make code more readable when used appropriately. Syntax Following is the syntax for the ternary operator − result = condition ? value_if_true : value_if_false; ...
Read MoreHow to print the first ten Fibonacci numbers using C#?
The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, starting from 0 and 1. In C#, we can generate and print the first ten Fibonacci numbers using loops and basic arithmetic operations. Understanding the Fibonacci Sequence The Fibonacci sequence begins with 0 and 1. Each subsequent number is calculated by adding the two previous numbers together − Fibonacci Sequence Pattern 0 1 1 ...
Read MoreC# program to multiply all numbers in the list
Multiplying all numbers in a list is a common programming task in C#. This can be achieved using several approaches including loops, LINQ, and recursion. The key is to initialize a variable to 1 (the multiplicative identity) and then multiply each element in the list. Syntax Following is the basic syntax for multiplying all numbers in a list using a foreach loop − List numbers = new List { 1, 2, 3 }; int product = 1; foreach (int number in numbers) { product *= number; } Using Foreach Loop ...
Read MoreC# program to create a ValueType with names
ValueTuples in C# allow you to create lightweight data structures with named fields. Introduced in C# 7, ValueTuples provide a convenient way to group multiple values together without creating a separate class or struct. Note − For .NET Framework projects, you may need to add the System.ValueTuple NuGet package to use ValueTuples. Installing System.ValueTuple Package To add the System.ValueTuple package to your project − Go to your project Right click on the project in the Solution Explorer Select "Manage NuGet Packages" Click the Browse tab and search for "System.ValueTuple" Install the System.ValueTuple package ...
Read MoreDictionary Class in C#
Dictionary in C# is a generic collection class that stores key-value pairs. It belongs to the System.Collections.Generic namespace and provides fast lookups based on keys. Each key in the dictionary must be unique, but values can be duplicated. Syntax Following is the syntax for declaring a Dictionary − public class Dictionary Where TKey is the type of keys and TValue is the type of values in the dictionary. To create and initialize a Dictionary − Dictionary dict = new Dictionary(); dict.Add(key, value); dict[key] = value; // Alternative way to add/update ...
Read MoreHow to compare two dictionaries in C#?
Comparing two dictionaries in C# involves checking whether they contain the same key-value pairs. This can be done through several approaches, from manual iteration to using LINQ methods for more concise solutions. Using Manual Iteration The most straightforward approach is to manually iterate through one dictionary and check if the other contains matching key-value pairs − using System; using System.Collections.Generic; class Program { public static void Main() { // Dictionary One IDictionary d1 = new Dictionary(); ...
Read More