小编Jbr*_*son的帖子

带枚举的Swift协议扩展

所以我有几个代表各种单位系统的枚举:

enum MassUnit:Double{
     case Pound = 453.59237, Ounce = 28.349523125, Gram = 1.0, Kilogram = 1000.0;
}
enum VolumeUnit:Double{
    case Teaspoon = 1, Tablespoon = 3, Cup = 48, Pint = 96, Quart = 192, Gallon = 768, Liter = 202.884136211, Milliliter = 0.202884136211
}
enum TimeUnit:Double{
    case Second = 1, Minute = 60, Hour = 3600, Day = 86400, Week = 604800, Year = 31536000
}
Run Code Online (Sandbox Code Playgroud)

我想做的是能够从一个单位转换到另一个单位,例如从一年到几秒.为此,我确保我的枚举的原始值对应于转换乘数,例如1 Min = 60秒.因此,给定某个单位的x量,转换就是简单的

x * rawValue1 / rawValue2 // rawValue2 = rawValue …
Run Code Online (Sandbox Code Playgroud)

enums protocols swift

10
推荐指数
1
解决办法
2697
查看次数

如何在c#中将小时数从h转换为hh

我能够将分钟转换为小时和分钟.例如,35分钟转换为0:35和65分钟转换为1:5.

但我希望它分别以前面两个例子的00:35和01:05的格式显示.这里有什么建议?

我尝试了下面的代码

        TimeSpan ts = TimeSpan.FromMinutes(intMins);           
        Console.WriteLine(string.Format("{0}:{1}", ts.Hours,  ts.Minutes ) );    
Run Code Online (Sandbox Code Playgroud)

.net c#

1
推荐指数
1
解决办法
131
查看次数

标签 统计

.net ×1

c# ×1

enums ×1

protocols ×1

swift ×1