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
Programming Articles
Page 64 of 2547
C# Program To Sort Student Names in Descending Order Using LINQ
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 MoreGet an enumerator that iterates through the Dictionary in C#
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 MoreWhat are some of the fastest way to read a text file line by line using C#?
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 MoreC# Program to Split a String Collections into Groups
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 MoreCheck if an array is read-only or not in C#
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 MoreBitwise OR operation between the elements of BitArray in C#
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 MoreC# Program to Trap Events From File
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 MoreCheck if a HashSet contains the specified element in C#
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 MoreHow to flatten a list using LINQ C#?
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 MoreC# Program to View the Access Date and Time of a File
Welcome to this tutorial on creating a C# program to view the access date and time of a file. This guide will show you how to use C#'s file handling capabilities to retrieve file metadata, specifically the last access timestamp. Understanding File Timestamps in C# C# provides robust support for file operations through the System.IO namespace. Every file has three important timestamps − Creation Time − When the file was first created Last Write Time − When the file was last modified Last Access Time − When the file was last opened or read ...
Read More