Skip to content

Constants

sancalle edited this page Oct 14, 2022 · 5 revisions

Typescript

const CONST_VALUE: string = "THIS IS A CONSTANT";

C#

In C# those are wrapped into a static class

namespace Codeverter
{
    public static class Helper
    {
        public const string CONST_VALUE = "THIS IS A CONSTANT";
    }
}

Supported types

string

public const string CONST_VALUE = "THIS IS A CONSTANT";

number

public const int CONST_VALUE = 1;

bool

public const bool CONST_VALUE = true;

array

public static readonly int[] NUMBERS = new int[] { 1, 2, 3 };
public static readonly string[] ANIMALS = new string[] { "cat", "dog", "horse" };

datetime

public static readonly DateTime CONST_VALUE = new DateTime(); // original constant assignation as comment

reference

public static readonly Foo CONST_VALUE = null; // original constant assignation as comment

GO

package codeverter

const CONST_VALUE string = "THIS IS A CONSTANT"

Supported types

string

const CONST_VALUE string = "THIS IS A CONSTANT"

number

const CONST_VALUE int = 1

bool

const CONST_VALUE bool = true

array

var NUMBERS []int = []int{1, 2, 3}
var ANIMALS []string = []string{"cat", "dog", "horse"}

datetime

var CONST_VALUE time.Time = time.Now() // original constant assignation as comment

reference

var CONST_VALUE Foo // original constant assignation as comment

Visual Basic

In Visual Basic those are wrapped into a Module

Namespace Codeverter
    Module Helper
        Const CONST_VALUE As String = "THIS IS A CONSTANT"
    End Module
End Namespace

Supported types

string

Const CONST_VALUE As String = "THIS IS A CONSTANT"

number

Const CONST_VALUE As Integer = 50

bool

Const CONST_VALUE As Boolean = true

array

ReadOnly CONSTANTG As Integer() = { 1, 2, 3 }
ReadOnly CONSTANTG As String() = { "cat", "dog", "horse" }

datetime

ReadOnly CONSTANT As Date = new DateTime() 'new Date()

reference

ReadOnly CONSTANT As Foo = New Foo() 'new Foo()

Type inference

Supported. For example:

Typescript

const CONST_VALUE = "THIS IS A CONSTANT";

C#

public const string CONST_VALUE = "THIS IS A CONSTANT";

GO

const CONST_VALUE string = "THIS IS A CONSTANT"

Visual Basic

Const CONST_VALUE As String = "THIS IS A CONSTANT"