We used to use it in VB like so :
I know there are other tech I can use instead but Is there similar thing in C# ?VB Code:
Public Sub a() Dim blah As String If blah = "" Then Exit Sub Else 'do this End If End Sub
Printable View
We used to use it in VB like so :
I know there are other tech I can use instead but Is there similar thing in C# ?VB Code:
Public Sub a() Dim blah As String If blah = "" Then Exit Sub Else 'do this End If End Sub
Yes, all functions in C# should return something (even if nothing)
Code:void MyFunc()
{
//Do Something
If(blah = "")
{
return;
}
Else
{
do this
}
}
You can also use break.
break wont leave the function, just the loop or select you are in!
if and else must be lowercase.
Does a void return value ?? and this code is wrong in C# !!! :confused:Quote:
Originally posted by Memnoch1207
Yes, all functions in C# should return something (even if nothing)
Code:void MyFunc()
{
//Do Something
If(blah = "")
{
return;
}
Else
{
do this
}
}
Is there any way else than Break (which is for loops and select) ?:rolleyes:
The code isn't 'wrong', just not formatted correctly because he probably just typed it in quickly. Here, this is right:Quote:
Does a void return value ?? and this code is wrong in C# !!!
Also, Void isn't a value. To verify this, try doing this:Code:void MyFunc(string blah)
{
if(blah = "NoProcess")
{
return;
}
else
{
// Do some work.
}
}
Object myObj = MyFunc("NoProcess");
You missed "==" in the if statement :D . This is not my question though , I was asking about Exit Sub in VB , Is there similar keyword in C# ?Quote:
Originally posted by hellswraith
The code isn't 'wrong', just not formatted correctly because he probably just typed it in quickly. Here, this is right:
Also, Void isn't a value. To verify this, try doing this:Code:void MyFunc(string blah)
{
if(blah = "NoProcess")
{
return;
}
else
{
// Do some work.
}
}
Object myObj = MyFunc("NoProcess");
Your right, I knew I would do something simple like that wrong...
Anyway, the
Exit Sub
equivlant in C# is just
return;
Just that simple.
In VB:
In C#:Code:Public Sub MyMethod()
' Blah blah blah code
If something = something Then
Exit Sub
End If
' more code.....
End Sub
Code:public void MyMethod()
{
// Blah blah blah code
if(something == something)
{
return;
}
// more code.....
}
Thanks all of you guys . It seems to be "return" what I want . :)