Articles on Trending Technologies

Technical articles with clear explanations and examples

How to print duplicate characters in a String using C#?

George John
George John
Updated on 17-Mar-2026 5K+ Views

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 More

How to generate a string randomly using C#?

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 722 Views

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 More

Different Methods to find Prime Numbers in C#

George John
George John
Updated on 17-Mar-2026 638 Views

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 More

Convert.ToSByte(String, IFormatProvider) Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 210 Views

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 More

Ternary Operator in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 3K+ Views

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 More

How to print the first ten Fibonacci numbers using C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 854 Views

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 More

C# program to multiply all numbers in the list

Samual Sam
Samual Sam
Updated on 17-Mar-2026 1K+ Views

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 More

C# program to create a ValueType with names

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 199 Views

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 More

Dictionary Class in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 993 Views

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 More

How to compare two dictionaries in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 4K+ Views

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
Showing 11341–11350 of 61,297 articles
Advertisements