MerlinVR / UdonSharp

An experimental compiler for compiling C# to Udon assembly
MIT License
678 stars 89 forks source link

Shift Array Elements Left? #75

Closed RyanKruse closed 3 years ago

RyanKruse commented 3 years ago

Hi, so I've encountered a programming exercise for shifting array elements left.

Current solutions on Stackoverflow involve ref variables or Array.Copy() which currently isn't exposed.

I've written my own method. Is the below code safe to use with UdonSharp?

public void ShiftArrayLeft(int[] array, int shiftAmount)
{
            if (shiftAmount <= 0) return;
            for (int i = shiftAmount; i < array.Length; i++)
            {
                        array[i - shiftAmount] = array[i];
                        array[i] = 0;
            }
}
MerlinVR commented 3 years ago

That looks fine. For future reference, the issues page is not the place to go for support. Consider joining the Discord.

RyanKruse commented 3 years ago

Ah yeah forgot about the Discord. I'll post there next time, thanks.