0

What I am trying to do is get input from the user and store it in a byte array. Please note, I must store var1 variable in a byte array and not a list.

Console.Write("Enter a number: ");
byte var1 = byte.Parse(Console.ReadLine());
byte[] byteArray = new byte[] {};
byteArray[0] = var1;
1
  • What's the question? Commented Mar 10, 2016 at 21:19

1 Answer 1

1

Arrays are fixed in size, you must specifiy the size of the array when you create it. In your example you told it to make an array of size 0 by putting the {} after the byte[]. Instead remove the {} and just put a 1 between the []

Console.Write("Enter a number: ");
byte var1 = byte.Parse(Console.ReadLine());
byte[] byteArray = new byte[1];
byteArray[0] = var1;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.