-2

How can I convert int to int[] and byte[] to byte[][].

I need to retrieve a list of data from database. I will store in the int[] and byte[][].

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
jumajiSis
  • 11
  • 5
  • 1
    Too vague. What kind of data are you handling, and what are you _really_ trying to do with it? What's the relation between the ints and the bytes? – Nyerguds May 09 '16 at 14:04
  • Have a look at this answer : :http://stackoverflow.com/questions/4580261/integer-to-integer-array-c-sharp – Beldi Anouar May 09 '16 at 14:05
  • If you're retrieving an integer then why not just store it in an integer?.. – Sayse May 09 '16 at 14:05
  • seems very odd i dont think you are expressing what you truly want. Try give an example if you can – Seabizkit May 09 '16 at 14:08

2 Answers2

1

There is no need to convert it. If you want to store a int into a int[] you have to create a new array and put it in the first possition.

Same with byte[]

int i = 1;
int[] i2 = new int[] { i };

byte[] b2 = new byte[] { 1 };
byte[][] b3 = new byte[][] { b2 };
fubo
  • 44,811
  • 17
  • 103
  • 137
0

It depends on what you want to store? int and byte store just 1 number or one byte.

int[] and byte[] are 1 dimensional arrays. Hence they store multiple int, and byte objects. Example:

int[] a = new int[]{1,2,3,4,5};

int[][] and byte[][] are 2 dimensional arrays. You can think of them that they store multiple int[] and byte[] arrays. Example:

int[,] a = new int[,] {{1,2}, {3,4}, {5,6}, {7,8}};

Think of it as having 2 rows:

{1,3,5,7} 
{2,4,6,8}
AdrianHHH
  • 13,492
  • 16
  • 50
  • 87