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
Thread Pools in C#
A thread pool in C# is a collection of pre-created threads that can be reused to execute multiple tasks efficiently. Instead of creating new threads for each task, the thread pool manages a pool of worker threads, reducing the overhead of thread creation and destruction. The ThreadPool class in the System.Threading namespace provides methods to queue work items for execution by background threads. When a thread completes its task, it returns to the pool and waits for the next available work item. Syntax Following is the syntax for queuing work items to the thread pool − ...
Read MoreC# Program to get the last write time of a file
To get the last write time of a file in C#, you can use the LastWriteTime property of the FileInfo class. This property returns a DateTime object representing when the file was last modified. You can also use the static File.GetLastWriteTime() method as an alternative approach for retrieving the last write time without creating a FileInfo instance. Syntax Using FileInfo class − FileInfo fileInfo = new FileInfo("filename.txt"); DateTime lastWrite = fileInfo.LastWriteTime; Using File.GetLastWriteTime() method − DateTime lastWrite = File.GetLastWriteTime("filename.txt"); Using FileInfo Class The FileInfo class provides comprehensive file ...
Read MoreC# Queryable Take() Method
The Take() method in C# is a LINQ extension method that returns a specified number of contiguous elements from the start of a sequence. It's commonly used with IQueryable collections to limit the number of results returned from a query. Syntax Following is the syntax for the Take() method − public static IQueryable Take( this IQueryable source, int count ) Parameters source − The IQueryable to return elements from. count − The number of elements to return. Return Value ...
Read MoreHow do you use a 'for loop' for accessing array elements in C#?
The for loop in C# executes a sequence of statements multiple times and is commonly used to iterate through arrays. It provides a clean way to access and manipulate array elements using an index variable that increments automatically. Syntax Following is the syntax for a for loop used with arrays − for (int i = 0; i < arrayName.Length; i++) { // Access array element using arrayName[i] } The for loop has three parts − Initialization: int i = 0 sets the starting index Condition: i < arrayName.Length continues ...
Read MoreDateTimeOffset.AddHours() Method in C#
The DateTimeOffset.AddHours() method in C# is used to add a specified number of whole and fractional hours to the value of a DateTimeOffset instance. This method returns a new DateTimeOffset object that represents the original date and time plus the specified hours, while preserving the original offset from UTC. Syntax Following is the syntax − public DateTimeOffset AddHours(double hours); Parameters hours − A double value representing the number of hours to add. This can be a whole number or fractional value. To subtract hours, provide a negative value. Return Value Returns ...
Read MoreC# Program to Convert Character case
Converting character case in C# is a common string manipulation task. The string class provides built-in methods ToLower() and ToUpper() to convert strings to lowercase and uppercase respectively. Syntax Following is the syntax for converting string case − string.ToLower() // Converts to lowercase string.ToUpper() // Converts to uppercase Both methods return a new string with the case converted and do not modify the original string. Using ToLower() Method The ToLower() method converts all uppercase characters in a string to lowercase − using System; ...
Read MoreProperties of the Thread Class
A thread is defined as the execution path of a program. Each thread defines a unique flow of control. The Thread class in C# provides various properties to manage and retrieve information about threads during execution. These properties allow you to control thread behavior, get thread status information, and manage cultural settings. Understanding these properties is essential for effective multithreading in C# applications. Thread Class Properties The following table describes the key properties of the Thread class − Property Description Type CurrentContext Gets the current context in which the ...
Read MoreC# Program to get the last access time of a file
To get the last access time of a file in C#, you can use the LastAccessTime property of the FileInfo class or the static File.GetLastAccessTime() method. The last access time represents when the file was last opened or read. Syntax Using the FileInfo class − FileInfo fileInfo = new FileInfo("filepath"); DateTime lastAccess = fileInfo.LastAccessTime; Using the static File.GetLastAccessTime() method − DateTime lastAccess = File.GetLastAccessTime("filepath"); Using FileInfo Class The FileInfo class provides an object-oriented approach to working with files. Here's how to get the last access time − ...
Read MoreDateTimeOffset.AddMilliseconds() Method in C#
The DateTimeOffset.AddMilliseconds() method in C# returns a new DateTimeOffset object that adds a specified number of milliseconds to the value of the current instance. This method is useful for precise time calculations where millisecond accuracy is required. The method accepts a double parameter representing the number of milliseconds to add. To subtract milliseconds, pass a negative value. The original DateTimeOffset instance remains unchanged as this method returns a new instance. Syntax Following is the syntax − public DateTimeOffset AddMilliseconds(double value); Parameters value − A double representing the number of milliseconds to ...
Read MoreC# Program to convert Digits to Words
Converting digits to words in C# involves breaking down a number into its individual digits and mapping each digit to its corresponding word representation. This technique is commonly used in financial applications, report generation, and number-to-text conversion systems. Algorithm Overview The conversion process follows these steps − Create an array of word strings for digits 0-9 Extract each digit from the number using modulo operation Store digits in reverse order (rightmost digit first) Map each digit to its corresponding word and display in correct order Digit-to-Word Conversion Process ...
Read More