Programming Articles

Page 868 of 2547

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 200 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

How to print one dimensional array in reverse order?

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

In C#, there are several ways to print a one-dimensional array in reverse order. You can either reverse the actual array using Array.Reverse() or print the elements in reverse without modifying the original array. Syntax Using Array.Reverse() to reverse the array − Array.Reverse(arrayName); Using a reverse loop to print without modifying the array − for (int i = arr.Length - 1; i >= 0; i--) { Console.WriteLine(arr[i]); } Using Array.Reverse() Method The Array.Reverse() method permanently reverses the order of elements in the array − ...

Read More

C# program to check for a string that contains all vowels

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

A C# program to check if a string contains all vowels involves examining the string to identify which vowels (a, e, i, o, u) are present. This is useful for word games, text analysis, or linguistic applications where you need to verify vowel completeness. Syntax The basic approach uses LINQ methods to filter and check for vowels − var vowels = str.Where(ch => "aeiouAEIOU".Contains(ch)).Distinct(); To check if all five vowels are present − bool hasAllVowels = vowels.Count() == 5; Using LINQ to Find All Vowels This approach uses the ...

Read More

Why is a Dictionary preferred over a Hashtable in C#?

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

In C#, Dictionary is generally preferred over Hashtable due to its better performance, type safety, and modern design. Both are key-value collections, but Dictionary provides significant advantages for most applications. A Hashtable is a non-generic collection that stores key-value pairs as object types, requiring boxing and unboxing operations. A Dictionary is a generic collection from the System.Collections.Generic namespace that provides compile-time type safety and better performance. Key Differences Feature Hashtable Dictionary Type Safety No compile-time type checking Strong type checking at compile-time Performance Slower due to boxing/unboxing Faster, ...

Read More

What is the IsReadOnly property of Hashtable class in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 171 Views

The IsReadOnly property of the Hashtable class in C# returns a boolean value indicating whether the Hashtable is read-only. When a Hashtable is read-only, you cannot add, remove, or modify its elements. By default, all Hashtable instances created using the standard constructor are not read-only, meaning they allow modifications. However, you can create read-only wrappers using specific methods. Syntax Following is the syntax for accessing the IsReadOnly property − bool isReadOnly = hashtable.IsReadOnly; Return Value The IsReadOnly property returns − true if the Hashtable is read-only false if the Hashtable ...

Read More

Dictionary.Values Property in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 367 Views

The Dictionary.Values property in C# is used to retrieve all the values stored in a Dictionary. This property returns a ValueCollection that contains all values from the dictionary, preserving the order in which they were added. Syntax Following is the syntax for the Dictionary.Values property − public Dictionary.ValueCollection Values { get; } Return Value The property returns a Dictionary.ValueCollection containing all the values in the dictionary. This collection is a live view of the dictionary values, meaning changes to the dictionary are reflected in the collection. Dictionary.Values Property ...

Read More
Showing 8671–8680 of 25,466 articles
« Prev 1 866 867 868 869 870 2547 Next »
Advertisements