George
George

Reputation: 2997

Multi Dimensional Byte Array In Kotlin

I have the following function in c#

public static byte[][] TagSplits(byte[][] splitArray, byte[] original, byte[] guid)
{
   byte[] temp;

   for (var a = 0; a < splitArray.Length; a++)
   {

   }
}

I am trying to convert the following code to Kotlin code, I have ended up with the following code:

companion object
{
    fun TagSplits(splitArray:  ByteArray, original: ByteArray, guid: ByteArray): ByteArray
    {

        var temp: ByteArray

        for(a in 0..splitArray.size)
        {

        }

    }
}

How would I be able to declare a multidimensional byte array in Kotlin as in the c# code base? For the input parameters for the

Upvotes: 1

Views: 795

Answers (2)

TheOperator
TheOperator

Reputation: 6466

Arrays do not have special syntax in Kotlin. There are two ways how to work with arrays:

  • Using the specialized types ByteArray, IntArray etc. These correspond to Java byte[], int[] arrays.
  • Using the generic type Array<T>. This corresponds to a Java array of references T[].

You can achieve the nesting using Array<ByteArray>, but probably there is a better way of achieving what exactly you need. Alternatives are List<ByteArray> or a more high-level OOP representation of the byte patterns.

Upvotes: 3

Miha_x64
Miha_x64

Reputation: 6363

ByteArray is an object (reference type), so you can create an array of it: Array<ByteArray>.

Upvotes: 2

Related Questions