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"?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With