我有这种扩展方法,但我不知道是否已有内置运算符或者是否有名称:
public static class IntegerExtensions
{
public static int DivideWholeAndPartial(this int total, int divisor)
{
return (total / divisor) +
((total % divisor) == 0 ? 0 : 1);
}
}
Run Code Online (Sandbox Code Playgroud)
基本上如果总数相等,则返回.如果有任何剩余部分,则将其四舍五入 - 即包括部分整体.有点像"需要多少一升瓶装3.5升水"的问题.
我错过了任何内置的C#方法吗?这有名字吗?
我想Ceiling
你做了什么:
return (int)Math.Ceiling((double)total / (double)divisor);
Run Code Online (Sandbox Code Playgroud)
..但我认为你必须保留你的扩展方法,因为没有内置方法可以做到这一点.