Programming Articles

Page 752 of 2547

How to return a string repeated N number of times in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 5K+ Views

There are several ways to repeat a string or character N number of times in C#. This article covers three effective approaches: using the string constructor for characters, string.Concat with Enumerable.Repeat, and StringBuilder for more complex scenarios. Using String Constructor for Characters The simplest way to repeat a single character is using the string constructor that takes a character and a count − string repeatedString = new string(character, count); Example using System; namespace DemoApplication { public class Program { ...

Read More

C# Program To Sort Student Names in Descending Order Using LINQ

Siva Sai
Siva Sai
Updated on 17-Mar-2026 389 Views

This tutorial demonstrates how to create a C# program that sorts student names in descending order using Language Integrated Query (LINQ). LINQ provides a powerful, readable way to query and manipulate data collections directly within C# code. Why Use LINQ for Sorting? LINQ offers several advantages over traditional sorting approaches − Readability − Clean, SQL-like syntax that's easy to understand Flexibility − Works with various data sources (collections, XML, databases) using the same syntax Abstraction − Focus on query logic rather than implementation details Lazy Evaluation − Query execution ...

Read More

Get an enumerator that iterates through the Dictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 606 Views

To get an enumerator that iterates through a Dictionary in C#, you use the GetEnumerator() method which returns an IDictionaryEnumerator. This enumerator provides access to both keys and values as you iterate through the dictionary's key-value pairs. Syntax Following is the syntax for getting a Dictionary enumerator − IDictionaryEnumerator enumerator = dictionary.GetEnumerator(); The enumerator is used with MoveNext() to advance through the collection − while (enumerator.MoveNext()) { Console.WriteLine("Key = " + enumerator.Key + ", Value = " + enumerator.Value); } Using Dictionary Enumerator with Integer Keys ...

Read More

What are some of the fastest way to read a text file line by line using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 2K+ Views

There are several fast and efficient ways to read a text file line by line in C#. The most commonly used methods are StreamReader.ReadLine, File.ReadLines, and File.ReadAllLines. Each method has its own advantages depending on the use case and file size. Using StreamReader.ReadLine StreamReader is the most memory-efficient approach for reading large files since it processes one line at a time without loading the entire file into memory. This method is ideal for processing very large files where memory usage is a concern. Example using System; using System.IO; using System.Text; namespace DemoApplication { ...

Read More

C# Program to Split a String Collections into Groups

Siva Sai
Siva Sai
Updated on 17-Mar-2026 568 Views

Welcome to this comprehensive tutorial on creating a C# program to split a collection of strings into groups using Language Integrated Query (LINQ). Whether you're a novice or an intermediate programmer, this guide will provide you with the insights necessary to understand the power of LINQ in C# and its applications in data manipulation. Understanding the Concept of Grouping in LINQ Grouping is a powerful concept in data manipulation that involves organizing data into categories based on specified criteria. In LINQ, the GroupBy method is used to group elements in a collection based on a key selector function. ...

Read More

Check if an array is read-only or not in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 317 Views

In C#, arrays are typically mutable by default, meaning their elements can be modified after creation. However, you can check if an array is read-only using the IsReadOnly property from the ICollection interface. The IsReadOnly property returns true if the array cannot be modified, and false if elements can be changed. Regular arrays in C# always return false for this property. Syntax Following is the syntax to check if an array is read-only − bool isReadOnly = arrayName.IsReadOnly; Using IsReadOnly Property Example The following example demonstrates how to check if an ...

Read More

Bitwise OR operation between the elements of BitArray in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 143 Views

The Bitwise OR operation between elements of BitArray in C# is performed using the Or() method. This method performs a logical OR operation on corresponding bits of two BitArray objects, returning true when at least one of the corresponding bits is true. Syntax Following is the syntax for performing Bitwise OR operation on BitArray − BitArray result = bitArray1.Or(bitArray2); Parameters bitArray2 − The BitArray with which to perform the bitwise OR operation. Return Value The method returns the current BitArray instance containing the result of the bitwise OR operation. ...

Read More

C# Program to Trap Events From File

Siva Sai
Siva Sai
Updated on 17-Mar-2026 343 Views

Welcome to our comprehensive guide on creating a C# program to trap events from a file. File event monitoring allows your application to respond to file system changes in real-time, making it useful for scenarios like log monitoring, file synchronization, and automated backup systems. Understanding FileSystemWatcher In C#, the FileSystemWatcher class monitors file system events and triggers notifications when files or directories are created, modified, deleted, or renamed. This class provides a powerful mechanism for building responsive applications that react to file system changes. FileSystemWatcher offers several key events − Created − Occurs when a ...

Read More

Check if a HashSet contains the specified element in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 905 Views

In C#, you can check if a HashSet contains a specified element using the Contains() method. This method returns true if the element exists in the HashSet, and false otherwise. The Contains() method provides O(1) average time complexity, making it very efficient for membership testing. Syntax Following is the syntax for using the Contains() method − bool result = hashSet.Contains(element); Parameters element − The element to locate in the HashSet. Return Value The Contains() method returns a bool value − true if the element is found in ...

Read More

How to flatten a list using LINQ C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 7K+ Views

Flattening a list means converting a List to List. For example, converting a List containing multiple integer lists into a single List with all elements combined. The SelectMany operator in LINQ is used to project each element of a sequence to an IEnumerable and then flatten the resulting sequences into one sequence. It combines records from a sequence of results and converts them into a single flattened result. Flattening Process [1, 2] [3, 4] ...

Read More
Showing 7511–7520 of 25,466 articles
« Prev 1 750 751 752 753 754 2547 Next »
Advertisements