|
-
Jul 8th, 2003, 07:02 PM
#1
Thread Starter
Sleep mode
Exit sub and C# equivalent ?[Resolved]
We used to use it in VB like so :
VB Code:
Public Sub a()
Dim blah As String
If blah = "" Then
Exit Sub
Else
'do this
End If
End Sub
I know there are other tech I can use instead but Is there similar thing in C# ?
Last edited by Pirate; Jul 9th, 2003 at 03:24 PM.
-
Jul 8th, 2003, 09:05 PM
#2
Frenzied Member
Yes, all functions in C# should return something (even if nothing)
Code:
void MyFunc()
{
//Do Something
If(blah = "")
{
return;
}
Else
{
do this
}
}
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jul 8th, 2003, 11:23 PM
#3
Frenzied Member
-
Jul 9th, 2003, 02:44 AM
#4
Hyperactive Member
break wont leave the function, just the loop or select you are in!
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
-
Jul 9th, 2003, 03:29 AM
#5
if and else must be lowercase.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jul 9th, 2003, 07:52 AM
#6
Thread Starter
Sleep mode
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
}
}
Does a void return value ?? and this code is wrong in C# !!!
-
Jul 9th, 2003, 08:37 AM
#7
Thread Starter
Sleep mode
Is there any way else than Break (which is for loops and select) ?
-
Jul 9th, 2003, 01:02 PM
#8
PowerPoster
Does a void return value ?? and this code is wrong in C# !!!
The code isn't 'wrong', just not formatted correctly because he probably just typed it in quickly. Here, this is right:
Code:
void MyFunc(string blah)
{
if(blah = "NoProcess")
{
return;
}
else
{
// Do some work.
}
}
Also, Void isn't a value. To verify this, try doing this:
Object myObj = MyFunc("NoProcess");
Last edited by hellswraith; Jul 9th, 2003 at 01:06 PM.
-
Jul 9th, 2003, 01:14 PM
#9
Thread Starter
Sleep mode
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:
Code:
void MyFunc(string blah)
{
if(blah = "NoProcess")
{
return;
}
else
{
// Do some work.
}
}
Also, Void isn't a value. To verify this, try doing this:
Object myObj = MyFunc("NoProcess");
You missed "==" in the if statement . This is not my question though , I was asking about Exit Sub in VB , Is there similar keyword in C# ?
-
Jul 9th, 2003, 02:39 PM
#10
PowerPoster
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:
Code:
Public Sub MyMethod()
' Blah blah blah code
If something = something Then
Exit Sub
End If
' more code.....
End Sub
In C#:
Code:
public void MyMethod()
{
// Blah blah blah code
if(something == something)
{
return;
}
// more code.....
}
Last edited by hellswraith; Jul 9th, 2003 at 02:42 PM.
-
Jul 9th, 2003, 03:22 PM
#11
Thread Starter
Sleep mode
Thanks all of you guys . It seems to be "return" what I want .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|