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 846 of 2547
DateTime.ToFileTimeUtc() Method in C#
The DateTime.ToFileTimeUtc() method in C# converts the value of the current DateTime object to a Windows file time. A Windows file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (UTC). This method is particularly useful when working with file systems, as Windows uses this format internally to store file timestamps. The method automatically converts the DateTime to UTC before performing the conversion. Syntax Following is the syntax − public long ToFileTimeUtc(); Return Value This method returns a long ...
Read MoreHow to list down all the files available in a directory using C#?
In C#, you can list all files in a directory using the DirectoryInfo class and its GetFiles() method. This approach provides detailed information about each file, including name, size, and other properties. Syntax Following is the syntax for creating a DirectoryInfo object and getting files − DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\path\to\directory"); FileInfo[] files = directoryInfo.GetFiles(); You can also specify search patterns and options − FileInfo[] files = directoryInfo.GetFiles("*.txt", SearchOption.TopDirectoryOnly); Using DirectoryInfo.GetFiles() The DirectoryInfo class provides detailed file information and is ideal when you need file properties like size, creation ...
Read MoreDecimal type in C#
The decimal type in C# is a 128-bit data type designed for financial and monetary calculations that require high precision. Unlike float and double, the decimal type provides exact decimal representation without rounding errors, making it ideal for applications involving currency and precise arithmetic operations. Syntax Following is the syntax for declaring decimal variables − decimal variableName = value; decimal variableName = valueM; // M or m suffix required for literals The M or m suffix is required when assigning decimal literals to distinguish them from double values − decimal price = ...
Read MoreWhat is the difference between initialization and assignment of values in C#?
In C#, initialization and assignment are two distinct concepts that are often confused. Understanding the difference is crucial for effective programming and memory management. Declaration vs Initialization vs Assignment Declaration creates a variable name, initialization allocates memory and sets initial values, and assignment changes the value of an already existing variable. Declaration → Initialization → Assignment Declaration int[] n; Creates variable name Initialization n = new int[5]; Allocates memory Assignment ...
Read MoreHow to loop through all values of an enum in C#?
In C#, you can loop through all values of an enum using the Enum.GetValues() method. This method returns an array containing all the values defined in the enum, which you can then iterate over using a foreach loop. Syntax Following is the syntax for looping through enum values − foreach (EnumType value in Enum.GetValues(typeof(EnumType))) { // Process each enum value } You can also use the generic version for type safety − foreach (EnumType value in Enum.GetValues()) { // Process each enum value (C# ...
Read MoreDecimal constants in C#
The decimal type in C# provides built-in constants to retrieve the minimum and maximum possible values for decimal numbers. These constants are useful for validation, range checking, and initialization purposes. Syntax Following is the syntax for declaring a decimal constant − decimal variableName = value M; Following is the syntax for accessing decimal constants − decimal.MaxValue // Maximum possible decimal value decimal.MinValue // Minimum possible decimal value Decimal Constants The decimal type provides two important constants − decimal.MaxValue − Returns the largest possible decimal ...
Read MoreC# OverflowException
The OverflowException in C# is thrown when an arithmetic operation results in a value that exceeds the range of the target data type. This commonly occurs during type conversions, arithmetic operations, or when parsing strings that contain values outside the acceptable range. Common Scenarios OverflowException is typically thrown in the following situations − Converting a string to an integer when the value exceeds int.MaxValue or int.MinValue Arithmetic operations that result in overflow (in checked context) Casting between numeric types where the source value is too large for the target type ...
Read MoreDateTime.ToLocalTime() Method in C#
The DateTime.ToLocalTime() method in C# converts a DateTime object to the local time zone of the current system. This method is particularly useful when working with UTC times or when you need to display times in the user's local time zone. Syntax Following is the syntax for the ToLocalTime() method − public DateTime ToLocalTime(); Return Value This method returns a new DateTime object that represents the local time equivalent of the current DateTime instance. If the original DateTime has Kind property set to DateTimeKind.Local, it returns the same value unchanged. How It ...
Read MoreC# Program to display priority of Thread
In C#, thread priority determines how the operating system schedules threads for execution. The Priority property of the Thread class allows you to both view and set the priority of a thread. Thread priority is represented by the ThreadPriority enumeration. Syntax To get the current thread and display its priority − Thread thread = Thread.CurrentThread; ThreadPriority priority = thread.Priority; To set a thread's priority − thread.Priority = ThreadPriority.High; ThreadPriority Enumeration Values Priority Level Description Lowest The thread has the lowest priority ...
Read MoreWhat are two-dimensional arrays in C#?
A two-dimensional array in C# is an array of arrays, where elements are arranged in rows and columns like a table or matrix. It stores data in a grid format with two indices: one for the row and one for the column. Two-dimensional arrays are useful for representing tabular data, matrices, game boards, or any data structure that requires a grid-like organization. Syntax Following is the syntax for declaring a two-dimensional array − datatype[, ] arrayName = new datatype[rows, columns]; Following is the syntax for initializing a two-dimensional array with values − ...
Read More