var duration = Duration.FromDays(4); Console.WriteLine(duration); // Output: 4.00:00:00
DateTime start = new DateTime(2021, 1, 1); DateTime end = new DateTime(2021, 1, 8); Duration duration = end - start; var days = duration.TotalDays; Console.WriteLine($"The duration is {days} days"); // Output: The duration is 7 daysIn this example, two DateTime objects are created to represent the start and end dates of a period. The duration between the two dates is calculated using the subtract operator (-), resulting in a duration object. The TotalDays property of the duration object is then used to extract the number of days in the duration. The output shows that the duration is 7 days. The Duration class is part of the System namespace in the .NET Standard library.