c# - Using delegates, anonymous(lambda) functions, and function pointers -


i have read little anonymous(lambda) functions , delegates. believe have dealing situation section of function could/should utilize them. not sure if assumptions correct.

current code:

fdosave(fgetsqlcheckempjob(), fgetsqlupdateempjob(), fgetsqlinsertempjob()); fdosave(fgetsqlcheckemppayrl(), fgetsqlupdateemppayrl(), fgetsqlinsertemppayrl()); fdosave(fgetsqlcheckeeo(), fgetsqlupdateeeo(), fgetsqlinserteeo()); fdosave(fgetsqlcheckempphone(), fgetsqlupdateempphone(), fgetsqlinsertempphone()); 

fgetsqlcheck...() - returns sql statement string returns count() of rows id fgetsqlupdate...() returns sql statement string update. fgetsqlinsert...() returns sql statement string insert. fdosave() either update or insert depending on value returned fgetcheck...()

the fgetsql functions this:

private string fgetsql...() {    stringbuilder sb = new stringbuilder();    //create sql statement    return sb.tostring(); } 

the fdosave functions looks this:

private void fdosave(string ssql_check, string ssql_update, ssql_insert) {    oracledatareader dr = erpdb.sqlgetdatareader(ssql_check);    while (dr.read())    {         if(fcheckifrecrodexists(dr) > 0) //if fgetsqlcheck...() found row specific id             //do update using ssql_update         else             //do insert using ssql_insert     } } 

can re-written using either lambda functions or delegates, , should it? how should re-written?

your question still vague, i'll put this.

cases:

1: reusable , "static"
if reuse sql statements , static, put them in properties. , consider better names.

2: reusable "variable" though simple
if reuse sql statements , variable doesn't use cpu, meaning change different states, , fast create , build, let them are.

3: reusable "variable" , complex
if reuse sql statements , variable complex , requires alot of cpu power, put them in method, call them delegates, not make them anonymous.

4: not-reusable "variable" , complex
if never reuse sql statements(which not ever case) , variable , complex , requires alot of cpu power, put them in anonymous function.

in cases
use better names.

my suggestion
prefer case 1 , 2, rest seems overly complex solution problem doesn't exist.
also, don't know entire codebase, don't object supposed saved isn't given fdosave().

i have done this:

// called upsert short "update or insert" public int save(empobj employeeobj)  {      if(checkifemployeeexists(employeeobj))      {          return update(employeeobj); // returns rows affected      }      else      {          return insert(employeeobj); // returns new id of employee.      } }  // other methods, select, update , insert statements lies  or gets called    , build public bool checkifemployeeexists(employeeobj) // check if employee exists public int update(employeeobj); // updates employee public int insert(employeeobj); // inserts employee 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -