Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在逐步函数列表中创建循环函数_C#_Loops - Fatal编程技术网

C# 在逐步函数列表中创建循环函数

C# 在逐步函数列表中创建循环函数,c#,loops,C#,Loops,现在,我得到的是: 它所做的是遍历预设函数的列表,该列表由用户配置。它通过循环遍历DataGridList来实现这一点,如下所示: foreach (DataGridRow row in configTable.Items) { ConfigRow crow = (ConfigRow)row.Item; //ConfigRow is just a generic class for the row values string val1 = crow.colValue;

现在,我得到的是:

它所做的是遍历预设函数的列表,该列表由用户配置。它通过循环遍历DataGridList来实现这一点,如下所示:

foreach (DataGridRow row in configTable.Items)
{
    ConfigRow crow = (ConfigRow)row.Item; //ConfigRow is just a generic class for the row values
    string val1 = crow.colValue;
    string val2 = crow.colValue2;
    //...Some other, irrelevant code for parsing user-set variables in the values...
    if (actions.actions.ContainsKey(crow.colType))
    {
        ((Action<String, String, String>)actions.actions[crow.colType]).Invoke(crow.colMethod, val1, val2);
    }
}

这个问题对我来说是一个谜,它让我很难受,因为它是一个非常大的功能,是最需要的。

关于循环的部分,你把我弄丢了。你能详细说明一下你想让程序处理这个循环吗?你的委托不能只包含一个循环吗?@usr这就是我的目标:。红色部分是第一个循环,橙色部分是嵌套在第一个循环中的第二个循环。这些环似乎形成了一棵树。此外,每个方法还必须接收一个允许该方法调用方法子对象的对象(如
Action invokeChildren
)。该方法将递归(反复)调用其他方法,从而遍历树。这是正确的方向吗?@usr我在考虑让
List inside=newlist()当它满足循环开始时,列表不包含其索引,它将把它添加到列表中,一旦满足循环结束时,它将返回到最后一个索引,或者如果满足了要求,它将删除它。因此,我之前发布的示例将有一个包含
3
8
的列表。这是个好主意吗?我的经验是,你不想在这么低的水平上胡闹。如果逻辑模型是一棵树,那么最好让数据结构确实形成一棵树。所有这些带有索引的计算都很难理解、测试和调试。;如果您想使用它,我认为您可以将循环开始索引设置为
堆栈
,它应该可以工作。您可以将堆栈作为
actions
中方法定义的输入。
Dictionary<string, Action<String, String, String>>
actions["Get source"] = (Action<String, String, String>)delegate(String method, String val1, String val2)
{
    using (WebClient wb = new WebClient())
    {
        if (method == "POST")
        {
            wb.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            variable = wb.UploadString(val1, val2);
        }
        else
        {
            variable = wb.DownloadString(val1);
        }
    }
window.appendConsole("Retrieved contents of '" + val1 + "' using " + method + " method");
};
loopA
loopB
...
stopB //loopA would stop at stopB and not stopA as it was intented to do.
stopA