Multidimensional Arrays and Copyto?

About Monkey 2 Forums Monkey 2 Programming Help Multidimensional Arrays and Copyto?

This topic contains 11 replies, has 5 voices, and was last updated by  Gerry Quinn 1 year, 9 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #8900

    Pakz
    Participant

    I was wondering how (or if it is possible) to copy a multidimensional array with the “Array.Copyto” command?

    At the moment I use for loops to copy the contenst of a multidimensional array.

    #8904

    Danilo
    Participant

    Could you use this?

    If you mean multimensional [10,10] arrays, I don’t know.

    #8910

    Pakz
    Participant

    Yeah, I was wondering how to do it with the [,] arrays. Maybe someone else knows.

    edit: I guess if you would create a function that returns a multidimensional array and inputs a multimimensional array you would be able to copy it that way.

    #8916

    abakobo
    Participant
    [/crayon]
    #8922

    Mark Sibly
    Keymaster

    There is no built-in way to do this yet (it’s easy for ‘2’ or ‘3’ dimensions, harder for ‘N’!) but abakobo’s solution look cool, although I’d probably rename it to Copy2DArray.

    #8924

    Pakz
    Participant

    Returning arrays from functions do not require you to copy each element. This is done automatically. Only the Return is needed 🙂

    #8925

    Pakz
    Participant

    I also tried to do this with the Lambda but I was not able fo figure out how to use the Typecasts <T>

    The regular way works.

     

    Lambda’s are kind of like functions but they can be put near the code that you are working with.

    #8926

    Danilo
    Participant

    @pakz:
    Looks like this is not a real copy:

    #8927

    Pakz
    Participant

    No, just checked it. You are right. Good to know.

    btw, anyone know how to do the typecast with the lambda’s?

    #8928

    Mark Sibly
    Keymaster

    Arrays are not copied automatically, ie: they are reference types.

    #8930

    Danilo
    Participant

    So @abakobo was right with his way of copying everything.

    We can make this for 3 dimensions:

    #8931

    Gerry Quinn
    Participant

    This was easy enough in Original Monkey, and I would imagine that a variation could be used in Monkey 2.  The trick was that if you already made a templated 1D array copy, you can then use it in your 2D one, and so on.  OFC you still need to make separate ones for as many dimensions as you think you’ll need, but not much coding is involved.  Here is the Monkey X version:

    Class for generic functions

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.