Reputation: 13
C# Question: I need to be able to create array of sets of bytes with a variable assigned to each set of bytes return that set of bytes to go through a for each loop function until the list is finished for example:
public static bytes[] OBJECTS()
{
return new bytes[3]
{
public static byte[] object1 = new byte[] { 0xB7, 0x79, 0xA0, 0x91 };
public static byte[] object2 = new byte[] { 0x4C, 0x80, 0xEB, 0x0E };
public static byte[] object3 = new byte[] { 0x5D, 0x0A, 0xAC, 0x8F };
};
}
EXAMPLE
I need to be able to return every value in the array to the for loop to perform functions with every set of bytes. Sorry for the confusion.
for (int i = 0; i < 3; ++i)
{
1st Loop Return Object 1
2st Loop Return Object 2
3rd Loop Return Object 3
}
Upvotes: 0
Views: 70
Reputation: 117057
This code most closely resembles the code in your question, but this is legal C#. How close is this to what you want?
void Main()
{
for (int i = 0; i < 3; ++i)
{
byte[] selected = OBJECTS()[i];
/* do something with `selected` */
}
}
public static byte[][] OBJECTS()
{
return new byte[][]
{
new byte[] { 0xB7, 0x79, 0xA0, 0x91 },
new byte[] { 0x4C, 0x80, 0xEB, 0x0E },
new byte[] { 0x5D, 0x0A, 0xAC, 0x8F },
};
}
This would be a better way to get each sub-array:
foreach (byte[] selected in OBJECTS())
{
/* do something with `selected` */
}
Upvotes: 1