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 833 of 2547
DateTimeOffset.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 MoreWhat are multicasting delegates in C#?
A multicasting delegate in C# is a delegate that holds references to multiple methods. When invoked, it calls all the methods in its invocation list sequentially. This is achieved using the += operator to add methods and -= operator to remove methods from the delegate. Multicasting delegates are particularly useful for implementing event-like behavior where multiple handlers need to be executed when a single event occurs. Syntax Following is the syntax for declaring a multicasting delegate − delegate returnType DelegateName(parameters); Adding and removing methods from a multicasting delegate − DelegateName del ...
Read MoreWhat is the difference between an interface and an abstract class in C#?
In C#, both interfaces and abstract classes provide a way to define contracts that derived classes must follow. However, they serve different purposes and have distinct characteristics that make them suitable for different scenarios. An interface defines a contract specifying what methods, properties, and events a class must implement, but provides no implementation itself. An abstract class can provide both abstract members (without implementation) and concrete members (with full implementation). Interface Syntax Following is the syntax for declaring an interface − public interface IInterfaceName { void MethodName(); string PropertyName ...
Read MoreGet the creation time of a file in C#
To get the creation time of a file in C#, you can use the CreationTime property of the FileInfo class or the static methods from the File class. This allows you to retrieve when a file was originally created on the file system. Syntax Using the FileInfo class − FileInfo fileInfo = new FileInfo("filename.txt"); DateTime creationTime = fileInfo.CreationTime; Using the static File class − DateTime creationTime = File.GetCreationTime("filename.txt"); Using FileInfo Class The FileInfo class provides an object-oriented approach to work with file information. Create a FileInfo object and access ...
Read MoreC# Program to Convert Decimal to Binary
Converting a decimal number to binary involves repeatedly dividing the decimal number by 2 and collecting the remainders. In C#, this can be accomplished using manual division or built-in methods like Convert.ToString(). The manual approach uses the division by 2 method where we divide the decimal number by 2, store the remainder, and continue until the quotient becomes 0. The binary representation is formed by reading the remainders in reverse order. Using Manual Division Method This method involves dividing the decimal number by 2 repeatedly and collecting remainders − Decimal to Binary ...
Read More