Given the following simple code snippet
// Worker method with implementation
public int DoCalculation(int receivingInt)
int multiply = receivingInt * 3;
return multiply;
// Caller method
public void CallerMethod(Object sender, Eventargs args)
int startingInt = 10;
int gettingVariable = DoCalculation(startingInt);
textbox1.text = gettingVariable.ToString();
The worker method has a method return type and therefore returns the int multiply variable which has stored the result from calling the DoCalculation method.
Now given the below code snippet
public Product GetProduct(int productId)
string sql = "some query implementation";
object[] parms = { "@ProductId", productId };
return DB.Read(sql, parms);
Why is the return keyword returning a static DB class and static Read method rather than return the local variables?
Ive never seen anything like this in methods where the return goes off to another method altogether, away from the usual worker and caller pattern...
Any more info needed please ask...
Cheers!
Loading

VulpesRank #55 · 29.2K reputationPosted Feb 18, 2012, 12:57 PM EST
Sam HobbsRank #107 · 20.5K reputationPosted Feb 19, 2012, 12:21 AM EST
Note that "DB.Read(sql, parms)" is an expression. A return statement uses an expression. If you have not seen return statements with expressions that are more than a single object (variable or whatever you want to call it) then it is only because you have not seen enough code. Now that you are seeing more code, you are becoming more experienced and encountering a greater variety of code.