Wish Initialize variable, types, list, etc. by the key word "new"

Alexander Stolte

Expert
Licensed User
Longtime User
Hey, i'm working with Visual Studio every day and there is a Feature to Initialize all with the keyword "new" for example:

Dim str as new string
Dim mytype as new nicetype

You could initialize lists for example in the Process_Globals already at the declaration.

Would that be possible someday?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User

Erel

B4X founder
Staff member
Licensed User
Longtime User
Not really dangerous. It depends on your requirements.

If you want to create a mutable list then write it like this:
B4X:
Dim list As List
list.Initialize
list.AddAll(Array(1, 2, 3))
Or:
B4X:
Sub CreateMutableList(Items As List) As List
 Dim list As List
 list.Initialize
 list.AddAll(Items)
 Return list
End Sub

Dim list As List = CreateMutableList(Array(1, 2, 3))
list.Add(4)
 
Top