Setting a function equivalent to something

I am converting a VB.Net program to C #. The programmer who wrote the VB.Net code stayed behind, so I can't ask him for help and I know very little about VB.net. In his program, he has the following:

public DataSet getData(string SQL)
{

  'Some variable declarations
  Dim ds As New DataSet

  Try
    'Some code
    getData = ds 'This is the part of the code I am having trouble figuring out.

  'some more code
}

      

So getData is the name of the function and it sets it to "ds" internally. So my question is, why are you setting a function equal to something within yourself? And what would be the correct C # version of "getData = ds"?

+3


source to share


1 answer


This is some VB syntax that means the return value of a function ds

. return ds;

would be equivalent in C #

From this page you can see that this is a valid return method in VB (emphasis mine)



Returning from a function

When the Function returns to the calling code, execution continues with a statement that follows an expression called a procedure.

To return a value from a function , you can either assign the value to the function name or include it in a Return statement.

However, I find it makes the code quite difficult to read, so I try to stay away from it and prefer returning

+5


source







All Articles