using System.Collections.Generic;
using System.Globalization;
public static void Main()
Console.WriteLine("IsPositive");
Console.WriteLine($"int {value} is positive {value.IsPositive().ToYesNoString()}");
Console.WriteLine($"int {value} is positive {value.IsPositive().ToYesNoString()}");
Console.WriteLine($"double {dValue} is positive {value.IsPositive().ToYesNoString()}");
Console.WriteLine($"double {dValue} is positive {value.IsPositive().ToYesNoString()}");
Console.WriteLine("---");
Console.WriteLine("GetRange");
var list = new List<string> { "abc", "def", "ghi" };
Range range = new Range(0, ^1);
List<string> subList1 = list.GetRange(range);
List<string> subList = list.GetRange(0..1);
Console.WriteLine($"{string.Join(",", subList1.ToArray())}");
Console.WriteLine($"{string.Join(",", subList.ToArray())}");
Console.WriteLine("---");
Console.WriteLine("ToDateTime");
TimeSpan timeSpan = new TimeSpan(1, 13, 3, 0);
DateTime dateTime = timeSpan.ToDateTime();
Console.WriteLine(dateTime);
public static class GenericExtensions
public static bool IsPositive<T>(this T value) where T : struct, IComparable<T> => value.CompareTo(default(T)) > 0;
public static bool IsNegative<T>(this T value) where T : struct, IComparable<T> => value.CompareTo(default(T)) == -1;
public static string ToYesNoString(this bool value) => value ? "Yes" : "No";
public static DateTime ToDateTime(this TimeSpan sender) => DateTime.ParseExact(sender.Formatted("hh:mm"), "H:mm", null, DateTimeStyles.None);
public static string Formatted(this TimeSpan sender, string format = "hh:mm tt") => DateTime.Today.Add(sender).ToString(format);
public static List<T> GetRange<T>(this List<T> list, Range range)
var(start, length) = range.GetOffsetAndLength(list.Count);
return list.GetRange(start, length);