计算具有三元组的方法中的计算步骤

问题描述 投票:1回答:1

我正在寻找一种方法以某种方式计算步数:

public static int Calculate0(int end, int init, int lim, int bon)
{
    return end <= 0
        ? 0

        : Math.Min(2 * lim, bon == 0 ? init : init + (2 * bon - lim / bon) * end);
}

我想我的问题有两个方面:

  1. 我不明白C#中的特殊qazxsw poi操作符
  2. 我不知道在哪里输入某种变量到:?方法。

一直在尝试通过Calculate0阅读关于:?运算符但我仍然很难理解Microsoft's guide内部发生的事情。

我的代码目前看起来像这样。这可能是正确的吗?

Calculate0

更新

我很抱歉让人困惑。我会试着把它缩小:我怎么能把计数器放到using System; namespace TestProject { internal class Program { private int calc0Steps = 0; public static void Main() { var calc0 = Program.Calculate0(1, 0, 1, 2); Console.WriteLine("Calculate: {0} | Steps: {1}", calc, calc0Steps); } public static int Calculate0(int end, int init, int lim, int bon) { return end <= 0 ? 0 : calc0Steps; Math.Min(2 * lim, bon == 0 ? init : init + (2 * bon - lim / bon) * end); } } }

我的主要工作范围是对fhcimolin提供的方法进行全面测试,并将此方法与Calculate0进行比较。一个小的任务是计算计算步骤。但我不知道我是如何在Calculate0实施计数器的。

我有另一个版本的Calculate0看起来像fhcimolin的答案,在那里我可以放入一个柜台。我需要计算两者中有多少计算步骤。

c#
1个回答
1
投票

如果我的逻辑正确,你可能希望你的Calculate0方法看起来像这样:

Calculate0

哪个相当于:

public static int Calculate0(int end, int init, int lim, int bon)
{
    return end <= 0 ? calc0Steps : Math.Min(2 * lim, bon == 0 ? init : init + (2 * bon - lim / bon) * end);
}
© www.soinside.com 2019 - 2024. All rights reserved.