Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Assigning values to a string array 22 Mar 2023 12:11 #25732

  • ic2
  • ic2's Avatar
  • Topic Author


  • Posts: 1667
  • 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:
    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

    Please Log in or Create an account to join the conversation.

    Assigning values to a string array 22 Mar 2023 12:35 #25733

    • leon-ts
    • leon-ts's Avatar


  • Posts: 280
  • Hello Dick,
    aReturn :=  <STRING>{"0", "0", "0", "EUR"}

    Best regards,
    Leonid
    Best regards,
    Leonid

    Please Log in or Create an account to join the conversation.

    Assigning values to a string array 22 Mar 2023 14:09 #25735

    • ic2
    • ic2's Avatar
    • Topic Author


  • Posts: 1667
  • Hello Leonid,

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

    Dick

    Please Log in or Create an account to join the conversation.

    Assigning values to a string array 22 Mar 2023 14:49 #25737

    • Meinhard
    • Meinhard's Avatar


  • Posts: 80
  • Dick,

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

    Regards
    Meinhard

    Please Log in or Create an account to join the conversation.

    Assigning values to a string array 22 Mar 2023 16:10 #25741

    • ic2
    • ic2's Avatar
    • Topic Author


  • Posts: 1667
  • 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:
    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[,]"
    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

    Please Log in or Create an account to join the conversation.

    Assigning values to a string array 22 Mar 2023 16:16 #25742

    • Chris
    • Chris's Avatar


  • Posts: 3982
  • 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)

    .
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Last edit: by Chris.

    Assigning values to a string array 22 Mar 2023 16:23 #25743

    • ic2
    • ic2's Avatar
    • Topic Author


  • Posts: 1667
  • 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

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1