![]() |
|
Basic Statements [VB/C#] - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Visual Basic & .NET Framework (https://sinister.ly/Forum-Visual-Basic-NET-Framework) +--- Thread: Basic Statements [VB/C#] (/Thread-Basic-Statements-VB-C) |
Basic Statements [VB/C#] - Shebang - 07-25-2014 ![]() Basic Statements in VB/C# Written by +.Shebang of +Reverence Introduction This is a basic overview of some of the most common (and less common) statements used within VB and C#, which are generally found in most programming languages. Code examples will be provided for both languages so you can learn for either one! There's a table of contents below that should make navigating this thread a little easier. Simply do Ctrl+F, and then the code next to each type of statement. This will allow you to easily jump to the statement you want if you're already familiar with the others. Table Of Contents A001: If...Else Statement A002: Select...Case Statement A003: Try...Catch...Finally Statement A004: Using...End Using Statement A001: If...Else Statement Basic Layout: Code: If <condition> Then
' Do something
ElseIf <condition> AndAlso <condition> OrElse <condition> Then
' Do something
Else
' Do something
End IfCode: if (condition) {
// do something
} else if (condition && condition || condition) {
// do something
} else {
// do something
}Code: If (bool1 = True AndAlso bool2 = False) OrElse (bool3 = False AndAlso int1 = 2)
' Do something
End IfCode: if ((bool1 == true && bool2 == false) || (bool3 == false && int1 == 2)) {
// do something
}A002: Select...Case Statement Basic Layout: Code: Select Case <value>
Case x to y, z, a, b
' Do something
Case c, d, e
' Do something
Case Else
' Do something
End SelectCode: switch (value) {
case 1:
// do something
break;
case 2:
// do something
break;
default:
// do something
break;
}A003: Try...End Try Statement Basic Layout: Code: Try
' Do something
Catch ex As Exception
' If error, do this
Finally
' Execute this regardless
End TryCode: try {
// do something
} catch (Exception ex) {
// if error, do this
} finally {
// execute this regardless
}A004: Using...End Using Statement Basic Layout: Code: Using obj As New Object
' Do something with the above object
End UsingCode: using (Object obj = new Object()) {
// do something
}Code: Dim obj As New Object
Try
obj.doWork()
Catch ex As Exception
' Handle exception
Finally
If obj IsNot Nothing Then
obj.Dispose()
End If
End TryCode: Object obj = new Object();
try {
obj.doWork();
} catch (Exception ex) {
// handle exception
} finally {
if (obj != null) {
obj.Dispose();
}
}Conclusion Well, that's everything! Hopefully this gave you enough information to use the statements with some knowledge of what actually goes on with them. If you're new, you can look forward to some tutorials I'll put out on loops and a few other things foun in languages based on the .NET Framework. |