Csharp Articles

Page 136 of 196

Null List in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 2K+ Views

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 More

C# Program to Subtract Two TimeSpan

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 491 Views

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 More

C# program to Loop over a two dimensional array

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 5K+ Views

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 More

C# program to display the next day

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 3K+ Views

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 More

C# Program to display the number of days in a month

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 806 Views

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 More

TimeSpan.From methods in C# ()

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 225 Views

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 More

C# Program to Add Two TimeSpan

George John
George John
Updated on 17-Mar-2026 741 Views

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 More

C# TicksPer constants

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 287 Views

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 More

Represent exact representation of no time in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 138 Views

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 More

Format TimeSpan in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 3K+ Views

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
Showing 1351–1360 of 1,951 articles
« Prev 1 134 135 136 137 138 196 Next »
Advertisements