-
Notifications
You must be signed in to change notification settings - Fork 0
Functions
sancalle edited this page Oct 14, 2022
·
2 revisions
function doFoo(): void {
}In C# those are wrapped into a static class
namespace Codeverter
{
public static class Helper
{
public static void DoFoo()
{
return;
}
}
}package codeverter
func DoFoo() {
return
}In Visual Basic those are wrapped into a Module
Namespace Codeverter
Module Helper
Public Sub DoFoo()
End Sub
End Module
End NamespaceThe body of the function is not converted. It is written as a comment to help with the manual migration.
function fibonacci(num: number): number {
if (num <= 1) {
return 1;
}
return fibonacci(num - 1) + fibonacci(num - 2);
}public static int Fibonacci(int num)
{
// if (num <= 1) {
// return 1;
// }
// return fibonacci(num - 1) + fibonacci(num - 2);
return 0;
}func Fibonacci(num int) int {
// if (num <= 1) {
// return 1;
// }
// return fibonacci(num - 1) + fibonacci(num - 2);
return 0
}Public Function Fibonacci(num As Integer) As Integer
' if (num <= 1) {
' return 1
' }
' return fibonacci(num - 1) + fibonacci(num - 2)
return 0
End FunctionThe declared variables and constants are converted. If those were declared and assigned by a constant value it will be considered.
If no type was provided, for example let varNum = 10; the type will be inferred (as numeric in this case).
function declareVars(): void {
let constValue = "random string";
let varNum = 10;
let varBool = true;
let varDate = new Date();
let varArray = [10]
let varRef = Crypto
}- string
- number
- boolean
- date => initialized with default value and the original one as a comment
- array
- reference => initialized with null and the original one as a comment
- string
- number
- boolean
- date => migrated as variable
- array => migrated as variable
- reference => migrated as variable
public static void DeclareVars()
{
string varStr = "random string";
int varNum = 10;
bool varBool = true;
DateTime varDate = new DateTime(); //new Date()
int[] varArray = new int[] { 10 };
Crypto varRef = null; //Crypto
// let varStr = "random string";
// let varNum = 10;
// let varBool = true;
// let varDate = new Date();
// let varArray = [10]
// let varRef = Crypto
return;
}- string
- number
- boolean
- date => initialized with default value and the original one as a comment
- array
- reference => initialized with a new instance and the original one as a comment
- string
- number
- boolean
- date => migrated as variable
- array => migrated as variable
- reference => migrated as variable
func DeclareVars() {
varStr := "random string"
varNum := 10
varBool := true
varDate := time.Now() // new Date()
varArray := []int{10}
varRef := new(Crypto) // Crypto
// let varStr = "random string";
// let varNum = 10;
// let varBool = true;
// let varDate = new Date();
// let varArray = [10]
// let varRef = Crypto
return
}- string
- number
- boolean
- date => initialized with default value and the original one as a comment
- array
- reference => initialized with null and the original one as a comment
- string
- number
- boolean
- date => migrated as variable
- array => migrated as variable
- reference => migrated as variable
Public Sub DeclareVars()
Dim constValue As String = "random string"
Dim varNum As Integer = 10
Dim varBool As Boolean = true
Dim varDate As Date = new DateTime() 'new Date()
Dim varArray As Integer() = { 10 }
Dim varRef As Crypto = Crypto 'Crypto
' let constValue = "random string"
' let varNum = 10
' let varBool = true
' let varDate = new Date()
' let varArray = [10]
' let varRef = Crypto
End Sub- If no return was provided at the function signature, it can be inferred by the return statement if it is constant.
- The return statement is assigned with a default value
function getOffset() {
return 100;
}public static int GetOffset()
{
// return 100;
return 0;
}func GetOffset() int {
// return 100;
return 0
}Public Function GetOffset() As Integer
' return 100
return 0
End FunctionParameters must have a type. We cannot infer the type yet.
function sum(val1: number, val2: number): number {
return val1 + val2;
}public static int Sum(int val1, int val2)
{
// return val1 + val2;
return 0;
}func Sum(val1 int, val2 int) int {
// return val1 + val2;
return 0
}Public Function Sum(val1 As Integer, val2 As Integer) As Integer
' return val1 + val2
return 0
End Function