Return multiple values from a method in C# -


issue not able values, first record available i.e pmdes1_01 other return values not captured, please code

public class dataxaero {     //create new method data xaero database     public static string getdata(string ordnum_10)     {         string pmdes1_01 = "";         string descrptn_104 = "";         string prtnum_10 = "";         string ordref_10 = "";         string tnxdte_01 = "";         //create connection         sqlconnection con = new sqlconnection(@"data source=xxx;initial catalog=xxx;integrated security=true;");          //sql command         sqlcommand cmd = new sqlcommand("select  ...............", con);           //open connection         con.open();         //to read sql server         sqldatareader dr = cmd.executereader();         while (dr.read())         {             pmdes1_01 = dr["pmdes1_01"].tostring();             prtnum_10 = dr["prtnum_10"].tostring();             descrptn_104 = dr["descrptn_104"].tostring();                             ordref_10 = dr["ordref_10"].tostring();             tnxdte_01 = dr["tnxdte_01"].tostring();          }          //close connections         dr.close();         con.close();         //get values          return pmdes1_01;         return prtnum_10; (get error here unreachable code detected)         return descrptn_104;                      return ordref_10;         return tnxdte_01; 

methods in .net don't support multiple return statements. if wish return multiple values, must returning collection. here's example:

public static list<string> getdata(string ordnum_10) {     //snip...      return new list<string> { pmdes1_01, prtnum_10, descrptn_104, ordref_10, tnxdte_01 }; } 

your calling code can extract values returned list.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -