我试图让这个函数中的参数...递归函数得到一个参数
public static int subsumer(string id,int acc,SqlConnection connection)
{
acc++;
SqlCommand cercas = new SqlCommand("select * from common_relation where id_source ='" + id + "' AND type='@' ", connection);
SqlDataReader leggsyn = null;
leggsyn = cercas.ExecuteReader();
int f = 0;
while (leggsyn.Read())
{
f= subsumer(leggsyn["id_target"].ToString(),acc,connection);
if (acc <= f)
{
acc = f;
}
}
//siamo arrivati alla fine
return acc-1;
}
每个周期参数acc
将递增和调试我看到在我的情况下,它达到值3 ,但在最后递归我总是0 ...我无法得到它...谢谢大家
你是什么意思'参数'?此外,为什么你使用字符串连接而不是使用正确的参数化查询?输入中的一个奇怪的字符会导致问题。更有趣的输入可能是'1; DROP TABLE COMMON_RELATION;'' – 2015-04-01 14:29:53
你是如何调用函数的?你有没有在调试器中检查它,确保你的逻辑是正确的? – 2015-04-01 14:31:16
你的功能假设要做什么?总数还是最大值? ,因为我看到你的循环中只有分配 没有增量 – 2015-04-01 14:43:44