Assigning values to a string array

This forum is meant for questions and discussions about the X# language and tools
Post Reply
ic2
Posts: 1819
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Assigning values to a string array

Post by ic2 »

Earlier we had an issue that a C# method returned a string array while in the (converted) VO code a VO array was used. Not sure why it worked in VO, but now we have done this:

Code: Select all

Local aReturn As String[,]
aReturn:=CSharpCalledMethod()		// This works
aReturn :=  {"0", "0", "0", "EUR"}	        // This gives an error
The error is:

Error XS0029 Cannot implicitly convert type 'array' to 'string[*,*]'

How do we fill a string array like in the 2nd line without getting this error?

The program needs the C# returned arrays as well as directly assigned arrays.

Dick
leon-ts
Posts: 431
Joined: Fri Feb 03, 2017 1:43 pm

Assigning values to a string array

Post by leon-ts »

Hello Dick,

Code: Select all

aReturn :=  <STRING>{"0", "0", "0", "EUR"}
Best regards,
Leonid
Best regards,
Leonid
ic2
Posts: 1819
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Assigning values to a string array

Post by ic2 »

Hello Leonid,

Thanks for your reply, but unfortunately the compiler error remains....

Dick
User avatar
Meinhard
Posts: 81
Joined: Thu Oct 01, 2015 4:51 pm

Assigning values to a string array

Post by Meinhard »

Dick,

you're declaring a multi dimensional array, but the literal you're trying to assing is an one dimensional array.

Regards
Meinhard
ic2
Posts: 1819
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Assigning values to a string array

Post by ic2 »

Hello Meinhard,

As I am unfamiliar with string arrays I did 't realize that. In VO we get a multi dim array indeed which we convert like this:

Code: Select all

aReturn := Array(CSharpCalledMethod())
Unfortunately ARRAY() doesn't work in X# to convert a string array to a VO array (multidim). So when we define aReturn as string[,] then the above code compiles.

But this still does not compile (with string[,]"

Code: Select all

	aReturn := {{"0", "0", "0", "EUR"}}
What are we missing? The question is revised as "how do we assign values to a multidim array?

And can we acces these arrays (once it finally works) the same way as VO style arrays?

Dick
User avatar
Chris
Posts: 4635
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Assigning values to a string array

Post by Chris »

Hi Dick,

Yes you can, and this is actually the current way to fill up a muti dim array:

LOCAL aReturn AS INT[,]
aReturn := INT[,]{1,4} // create array with dimension a=1,b=4
aReturn[1,1] := "0"
aReturn[1,2] := "0"
aReturn[1,3] := "0"
aReturn[1,4] := "EUR"

It's in the todo list to provide a syntax for initializing also multidim arrays in a single line (for single dim arrays, you can do it as Leonid showed)

.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
ic2
Posts: 1819
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Assigning values to a string array

Post by ic2 »

Hello Chris,

Indeed, assigning every single element works, thanks!
Frank will now check if accessing the values works as it did and then we are one step further.

Dick
Post Reply