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
Server Side Programming Articles
Page 825 of 2109
C# Program to get current day of week
Use the DateTime.DayOfWeek property to get the current day of the week in C#. This property returns a DayOfWeek enumeration value representing the day. Syntax Following is the syntax to get the current day of the week − DayOfWeek dayOfWeek = DateTime.Today.DayOfWeek; You can also use DateTime.Now.DayOfWeek to include the current time − DayOfWeek dayOfWeek = DateTime.Now.DayOfWeek; Using DateTime.Today.DayOfWeek The DateTime.Today property gets the current date with the time component set to 00:00:00. Using DayOfWeek on this returns the current day as an enumeration value − using ...
Read MoreGenerate current month in C#
To generate the current month in C#, you can use the DateTime.Now property to get the current date and time, then extract the month information using various properties and formatting methods. Syntax Following is the syntax to get the current date − DateTime dt = DateTime.Now; Following is the syntax to get the month as a number − int month = dt.Month; Following is the syntax to get the month name using formatting − string monthName = dt.ToString("MMMM"); Getting Current Month as Number The Month ...
Read MoreHow to initialize an empty DateTime in C#
In C#, there are several ways to initialize an empty or default DateTime value. The most common approach is using DateTime.MinValue, which represents the minimum possible date and time value in the .NET framework. Syntax Following are the different ways to initialize an empty DateTime − DateTime dt1 = DateTime.MinValue; DateTime dt2 = new DateTime(); DateTime dt3 = default(DateTime); Using DateTime.MinValue The DateTime.MinValue property returns the minimum possible DateTime value, which is January 1, 0001 at 12:00:00 AM − using System; public class Demo { public static ...
Read MoreC# General Date Short Time ("g") Format Specifier
The General Date Short Time ("g") format specifier in C# is a standard DateTime format that combines the short date pattern ("d") and short time pattern ("t"), separated by a space. This format provides a compact representation of both date and time information. Syntax Following is the syntax for using the "g" format specifier − dateTime.ToString("g") dateTime.ToString("g", CultureInfo) The format pattern varies based on the current culture or specified culture. It typically displays − Short date − MM/dd/yyyy or dd/MM/yyyy depending on culture Short time − HH:mm or h:mm tt (12-hour with ...
Read MoreC# DateTime Max Value
The DateTime.MaxValue property in C# returns the maximum possible value for a DateTime object. This represents the largest date and time that can be stored in a DateTime structure, which is December 31, 9999 at 11:59:59.9999999 PM. This property is useful when you need to initialize a DateTime variable with the highest possible value, compare dates to find the maximum, or set upper bounds in date range validations. Syntax Following is the syntax for accessing the maximum DateTime value − DateTime maxValue = DateTime.MaxValue; DateTime MaxValue Example The following example demonstrates how ...
Read MoreC# Program to return specified number of elements from the end of an array
The TakeLast() method in C# returns a specified number of elements from the end of a sequence. It's part of the LINQ library and provides an efficient way to extract the last few elements from arrays, lists, or other enumerable collections. Syntax Following is the syntax for using TakeLast() − IEnumerable TakeLast(int count) Parameters count − The number of elements to return from the end of the sequence. Return Value Returns an IEnumerable containing the specified number of elements from the end of the source sequence. Using TakeLast() ...
Read MoreC# TimeSpan Min value
The TimeSpan structure in C# represents a time interval or duration. The TimeSpan.MinValue property returns the minimum possible value that a TimeSpan can represent, which is approximately -10.7 million days. This minimum value is useful when you need to initialize a TimeSpan variable to the smallest possible value or when performing comparisons to find the minimum time span in a collection. Syntax Following is the syntax to access the minimum TimeSpan value − TimeSpan.MinValue Return Value The TimeSpan.MinValue property returns a TimeSpan object representing the minimum possible time interval, which equals approximately ...
Read MoreC# TimeSpan Max value
The TimeSpan structure in C# represents a time interval or duration. The TimeSpan.MaxValue property returns the maximum possible value that a TimeSpan can represent. Syntax Following is the syntax to get the maximum TimeSpan value − TimeSpan.MaxValue Return Value The MaxValue property returns a TimeSpan object representing the maximum time span value, which is approximately 10.7 million days or about 29, 227 years. TimeSpan.MaxValue Breakdown 10675199.02:48:05.4775807 Days: 10, 675, 199 Hours: 02 ...
Read MoreC# Program to get the absolute value of the time
To get the absolute value of time, use the TimeSpan.Duration()
Read MoreC# Console BufferHeight Property
The Console.BufferHeight property in C# gets or sets the height of the buffer area in rows. The buffer height represents the maximum number of text rows that can be stored in the console's internal buffer before older lines are discarded. This property is particularly useful when you need to control how much output history the console retains or when working with console applications that produce large amounts of output. Syntax Following is the syntax for using the BufferHeight property − // Get buffer height int height = Console.BufferHeight; // Set buffer height Console.BufferHeight = ...
Read More