CKTIS / C#
System.TimeSpan: odniesienie praktyczne
System.TimeSpan: odniesienie praktyczne: TimeSpan reprezentuje czas trwania jako liczbę ticków, nie datę ani strefę.
Wersja: .NET API; verified against .NET 10 reference surface
Składnia
System.TimeSpan /* select a documented member or constructor */TimeSpan reprezentuje czas trwania jako liczbę ticków, nie datę ani strefę.
Stosuj do timeoutów i różnic czasu w obsługiwanym zakresie.
Właściwości Hours/Minutes są składowymi; do całkowitej wartości użyj TotalHours/TotalMinutes.
Operacje poza zakresem zgłaszają OverflowException; parsowanie zależy od formatu i kultury.
Kompletny program rzeczywiście używa System.TimeSpan; oczekiwany stdout to dokładnie 1.5.
Przykłady
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
var duration = TimeSpan.FromMinutes(90);
Console.WriteLine(duration.TotalHours.ToString("0.0", CultureInfo.InvariantCulture));
Wynik
1.5
Kompletny program rzeczywiście używa `System.TimeSpan`; oczekiwany stdout to dokładnie `1.5`.