Reputation: 4028
I am calling a function as:
string judge1 = abs.getjud1(this.HiddenField4, this.TextBox3);
The function being called is:
public string getjud1(HiddenField HiddenField4, TextBox TextBox3)
{
String dbDate = DateTime.ParseExact(TextBox3.Text, "dd/mm/yyyy", null).ToString("yyyy-mm-dd");
try
{
OdbcConnection casetype = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=10.155.160.130;Database=testcase;User=root;Password=;Option=3;");
casetype.Open();
//*********to get jud1
string jud1query = "select jname from testcase.orddetpabak,testcase.judge where orddetpabak.jud1 = judge.jcode and fil_no=? and orderdate=?;";
//*********to get jud1
OdbcCommand jud1cmd = new OdbcCommand(jud1query, casetype);
jud1cmd.Parameters.AddWithValue("?", HiddenField4.Value);
jud1cmd.Parameters.AddWithValue("?", dbDate);
using (OdbcDataReader jud1MyReader = jud1cmd.ExecuteReader())
{
while (jud1MyReader.Read())
{
judge1 = jud1MyReader["jname"].ToString();
Globals.jjj1= "J";
}
}
}
catch (Exception ep)
{ }
return judge1;
}
I want to return judge1 and Globals.jjj1, is it possible to do that? If so than how to do it?
Upvotes: 0
Views: 264
Reputation: 3567
Since C# is an object oriented language, why not simply make an object that contains all the values that you want to return? That way you only have one variable for your return statement, but you have access to all the values that you require.
Upvotes: 0
Reputation: 1589
Not quite sure what you mean, but if you want to return multiple values, you can use the out
or ref
keywords.
void SomeFunction()
{
int value1;
int value2;
value1 = SomeOtherFunction(out value2);
//Value1 now equals 21, value2 equals 25.
//You can use the same thing for strings.
}
int SomeOtherFunction(out int value2)
{
value2 = 25;
return 21;
}
Upvotes: 0
Reputation: 60694
You can only return one object from your method, but you have two options here:
out
, and set the value of that parameter inside the method. The variable you send into the method as a parameter will then be updated outside the method as well.Upvotes: 0
Reputation: 7630
Create an object with the 2 string values that represent the values you want and then return the object.
public MyCustomObject getjud1(HiddenField HiddenField4, TextBox TextBox3)
Upvotes: 0
Reputation: 6916
Return a Tuple
http://msdn.microsoft.com/en-us/library/system.tuple.aspx
Upvotes: 1