recursion - recursive function in c# get a parameter -


i'm trying parameter function...

public static int subsumer(string id,int acc,sqlconnection connection)  {     acc++;     sqlcommand cercas = new sqlcommand("select * common_relation id_source ='" + id + "' , 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; } 

each cycle parameter acc increment , debugging see in case reach value 3, in final recursion 0...i can't it...thank all

by returning acc - 1, decrementing f returned recursive call , don't think that's expect.

public static int subsumer(string id,int acc,sqlconnection connection)  {     sqlcommand cercas = new sqlcommand("select * common_relation id_source ='" + id + "' , type='@' ", connection);     sqldatareader leggsyn = null;     leggsyn = cercas.executereader();      int f = 0;     while (leggsyn.read())      {         f=  subsumer(leggsyn["id_target"].tostring(),acc + 1,connection);         if (acc <= f)          {              acc = f;          }       }       //siamo arrivati alla fine     return acc; } 

on side note, querying recursively isn't design choice. querying recursively readers open each call on stack worse. not using query parmeters bad thing.


Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -