Home > Backend Development > C#.Net Tutorial > C# program to add two time spans

C# program to add two time spans

WBOY
Release: 2023-09-23 10:05:06
forward
1164 people have browsed it

添加两个时间跨度的 C# 程序

First, set up two TimeSpans -

TimeSpan t1 = TimeSpan.FromMinutes(1);
TimeSpan t2 = TimeSpan.FromMinutes(2);
Copy after login

To add it, use the Add() method -

TimeSpan res = t1.Add(t2);
Copy after login

Example

Using System;
using System.Linq;
public class Demo {
   public static void Main() {
      TimeSpan t1 = TimeSpan.FromMinutes(1);
      TimeSpan t2 = TimeSpan.FromMinutes(2);
      Console.WriteLine("First TimeSpan: "+t1);
      Console.WriteLine("Second TimeSpan: "+t2);
      // Adding
      TimeSpan res = t1.Add(t2);
      Console.WriteLine("Resultant TimeSpan: "+res);
   }
}
Copy after login

The above is the detailed content of C# program to add two time spans. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template