xsharp.eu • Assigning values to a string array
Page 1 of 1

Assigning values to a string array

Posted: Wed Mar 22, 2023 11:11 am
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

Assigning values to a string array

Posted: Wed Mar 22, 2023 11:35 am
by leon-ts
Hello Dick,

Code: Select all

aReturn :=  <STRING>{"0", "0", "0", "EUR"}
Best regards,
Leonid

Assigning values to a string array

Posted: Wed Mar 22, 2023 1:09 pm
by ic2
Hello Leonid,

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

Dick

Assigning values to a string array

Posted: Wed Mar 22, 2023 1:49 pm
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

Assigning values to a string array

Posted: Wed Mar 22, 2023 3:10 pm
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

Assigning values to a string array

Posted: Wed Mar 22, 2023 3:16 pm
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)

.

Assigning values to a string array

Posted: Wed Mar 22, 2023 3:23 pm
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