Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a Function Equal to Something

Tags:

c#

vb.net

I am converting a VB.Net program to C#. The programmer who wrote the VB.Net code left so I cannot ask him for help, and I have very little knowledge of 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 he is setting it to "ds" within itself. So my question is, why would you set the function equal to something within itself? And what would be the correct C# version of "getData = ds"?

like image 212
Jared.Rodgers Avatar asked May 20 '26 15:05

Jared.Rodgers


1 Answers

This is some VB syntax that means that the return value of the function is ds. return ds; would be the 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 procedure returns to the calling code, execution continues with the statement that follows the statement that called the 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 this makes the code quite hard to read, so i tend to stay away from it and prefer the return

like image 189
samy Avatar answered May 23 '26 04:05

samy