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
Csharp Articles
Page 136 of 196
Null List in C#
A null list in C# refers to a List reference that points to nothing instead of an actual List object. This is different from an empty list, which is an initialized List with zero elements. Understanding null lists is crucial for avoiding NullReferenceException errors in your applications. Syntax To declare a null list − List listName = null; To check if a list is null − if (listName == null) { // handle null case } Creating and Checking Null Lists When you declare a List ...
Read MoreC# Program to Subtract Two TimeSpan
In C#, the TimeSpan structure represents a time interval and provides methods to perform arithmetic operations. To subtract one TimeSpan from another, you can use the Subtract() method or the subtraction operator (-). Syntax Following is the syntax for subtracting TimeSpan objects using the Subtract() method − TimeSpan result = timeSpan1.Subtract(timeSpan2); Following is the syntax using the subtraction operator − TimeSpan result = timeSpan1 - timeSpan2; Using Subtract() Method The Subtract() method returns a new TimeSpan that represents the difference between two TimeSpan values − using System; ...
Read MoreC# program to Loop over a two dimensional array
A two-dimensional array in C# stores elements in a grid format with rows and columns. To loop through all elements, you need to iterate through both dimensions using nested loops. Syntax Following is the syntax for declaring a two-dimensional array − dataType[,] arrayName = new dataType[rows, columns]; Following is the syntax for looping through a two-dimensional array using nested for loops − for (int i = 0; i
Read MoreC# program to display the next day
To display the next day in C#, use the AddDays() method with a value of 1. The AddDays() method adds or subtracts days from a DateTime object and returns a new DateTime representing the modified date. Syntax Following is the syntax for using AddDays() method − DateTime.AddDays(double value) Parameters value − A number of whole and fractional days. Use positive values for future dates and negative values for past dates. Return Value The method returns a new DateTime object that represents the date and time with the ...
Read MoreC# Program to display the number of days in a month
The DateTime.DaysInMonth() method in C# is used to display the number of days in a specific month and year. This static method is particularly useful when working with calendar calculations or when you need to validate dates. Syntax Following is the syntax for using DateTime.DaysInMonth() − int days = DateTime.DaysInMonth(year, month); Parameters year: An integer representing the year (1 to 9999). month: An integer representing the month (1 to 12). Return Value Returns an integer representing the number of days in the specified month and ...
Read MoreTimeSpan.From methods in C# ()
The TimeSpan.From methods in C# provide a convenient way to create TimeSpan objects from specific time units. These static methods include FromDays, FromHours, FromMinutes, FromSeconds, FromMilliseconds, and FromTicks. Each method takes a numeric value and returns a TimeSpan representing that duration in the specified unit. This approach is more readable than manually calculating ticks or using TimeSpan constructors. Syntax Following are the syntax formats for the most commonly used TimeSpan.From methods − TimeSpan.FromDays(double value) TimeSpan.FromHours(double value) TimeSpan.FromMinutes(double value) TimeSpan.FromSeconds(double value) TimeSpan.FromMilliseconds(double value) TimeSpan.FromTicks(long value) Parameters All TimeSpan.From methods (except FromTicks) accept a ...
Read MoreC# Program to Add Two TimeSpan
The TimeSpan structure in C# represents a time interval and provides methods to perform arithmetic operations. You can add two TimeSpan objects using the Add() method or the + operator to get the combined duration. Syntax Following is the syntax for adding two TimeSpan objects using the Add() method − TimeSpan result = timespan1.Add(timespan2); You can also use the + operator for addition − TimeSpan result = timespan1 + timespan2; Using the Add() Method The Add() method returns a new TimeSpan that represents the sum of two time intervals ...
Read MoreC# TicksPer constants
The TicksPer constants in C# are predefined values in the TimeSpan class that represent the number of ticks for different time units. A tick is the smallest unit of time measurement in .NET, where one tick equals 100 nanoseconds. These constants help convert between ticks and common time measurements. Available TicksPer Constants The TimeSpan class provides the following TicksPer constants − TicksPerDay − Number of ticks in one day TicksPerHour − Number of ticks in one hour TicksPerMinute − Number of ticks in one minute TicksPerSecond − Number of ticks in one second TicksPerMillisecond − Number ...
Read MoreRepresent exact representation of no time in C#
The TimeSpan.Zero property in C# represents the exact representation of no time, which displays as 00:00:00. This is a static readonly field that provides a convenient way to initialize or compare TimeSpan values when you need to represent zero duration. Syntax Following is the syntax for using TimeSpan.Zero − TimeSpan timespan = TimeSpan.Zero; You can also use it for comparison operations − if (timespan == TimeSpan.Zero) { // timespan represents no time } Using TimeSpan.Zero for Initialization The most common use of TimeSpan.Zero is to initialize ...
Read MoreFormat TimeSpan in C#
The TimeSpan class in C# represents a time interval and provides several formatting options to display time in different formats. You can format a TimeSpan using standard format strings, custom format strings, or the ToString() method with format specifiers. Syntax Following is the syntax for formatting a TimeSpan using custom format strings − timeSpan.ToString("format_string") Following is the syntax for formatting using composite formatting − string.Format("{0:format_string}", timeSpan) Using Standard Format Strings TimeSpan supports standard format strings like "c" (constant format), "g" (general short), and "G" (general long) − ...
Read More