Creating an empty .net array: syntax?

This forum is meant for questions and discussions about the X# language and tools
Post Reply
kitz
Posts: 87
Joined: Wed Nov 29, 2017 8:56 am

Creating an empty .net array: syntax?

Post by kitz »

Hi!
How do I create an empty .net array with count of elements out of a variable?
VO:
local aArray as array
iElements := 100
aArray := ArrayCreate( iElements )

X#:
local aX as string[]
iElements := 100
aX := ???

I am aware of
aX := <string>{"Alpha", "Beta"}
but how do I create one without literals?

BR Kurt
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Creating an empty .net array: syntax?

Post by wriedmann »

Hi Kurt,

Code: Select all

aData := string[]{ 10 }
Please see also here: https://docs.xsharp.it/doku.php?id=net_array

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
kitz
Posts: 87
Joined: Wed Nov 29, 2017 8:56 am

Creating an empty .net array: syntax?

Post by kitz »

Thanks Wolfgang!
Now it works!
Was already looking in these docs, but blind...
I had tried aX := <string[]>{ iElements }
There I got "cannot implicitly convert type 'int' to 'string[]'

BR Kurt
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Creating an empty .net array: syntax?

Post by wriedmann »

Hi Kurt,

the wiki has a search box in the upper right corner <g>.

Put "array" there and click on the search button. The correct article will be at top with 15 hits.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply