Guide to Game Development/The Programming Language/VB.NET/Basic math operators and Concatenation
The four basic math operations
editThe four basic operations can be used between: two constants, a variable and a constant and two variables.
+ - * /
Examples:
Dim Num1, Num2, Num3 as Integer
Num2 = 10
Num3 = 4
Num1 = Num2 + Num3
Console.WriteLine(Num1)
Num1 = 10-5
Console.WriteLine(Num1)
Num1 = Num2 * 3
Console.WriteLine(Num1)
Num1 = 12 / Num2
Console.WriteLine(Num1)
This code could be condenced to not need a Num1 like so:
Dim Num2 as Integer = 10
Dim Num3 as Integer = 4
Console.WriteLine(Num2 + Num3)
Console.WriteLine(10-5)
Console.WriteLine(Num2 * 3)
Console.WriteLine(12 / Num2)
Output:
14 5 30 3
Powers
editPowers can be done by the symbol ^ Example use:
Console.WriteLine(2^10)
Output:
1024
Other mathematical operators
editFor additional math operators, click here.
String Concatenation
editThis is the joining of two strings to make one. To do this you can either use + or &. Example of joining two strings:
Dim Str1 as String = "Hello " & "World" + "!"
Console.WriteLine(Str1)
Console.WriteLine("Hello " & "World" + "!")
Output:
Hello World! Hello World!
You can also do this with numbers and strings:
Dim Num1 as Integer = 6
Dim Str1 as String = "Your number: " & Num1 & " + 4 = " & Num1 + 4
Console.WriteLine(Str1)
Output:
Your number 6 + 4 = 10