How can I shorten this small piece of code?

I'm using sockets in my application, so for the most part, I'm using byte arrays..

Now, I'd like to shorten this code:

Dim OutData(3) As Byte
OutData(0) = 0
OutData(1) = 0
OutData(2) = 0
OutData(3) = 1

SendCommand is a function I wrote that accepts a byte array, puts some headers onto it, and sends it via TCP. The problem shows up when I have say a 32 byte string to send.

I know I could possible do something like this:

SendCommand(ASCII.GetBytes(Chr(0) & Chr(0) & Chr(0) & Chr(1)))

But that's kind of ugly with all the Chr's.

Can I do something like this? This doesn't work, but there has to be something similar:

SendCommand(New Byte() = {0, 0, 0, 1})

in the same way you could do New TYPE = VALUE
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

How about:

Dim OutData(3) as byte = 0
OutData(3) = 1

I wonder if all of the array elements would be set to 0 in the DIM, and then you just change the one you want as 1 to 1. :)
Hmm, I just tried it and it didn't work...

This did though:

Dim OutData() As Byte = {0, 0, 0, 1}

todd_Author Commented:
Yes, I was also aware of that, but I wanted to do it without a separate variable, and preferrably in one line.
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Class Outdata
   Dim Data(3) as byte

   Sub New()
      Data(0) = 0
      Data(1) = 0
      Data(2) = 0
      Data(3) = 1

SendCommand(Dim OD as new OutData)

There. :)
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
Your first try was ok, I always does like this, only that it had a small typo, try like this:

SendCommand(New Byte() {0, 0, 0, 1})

This works fine.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
Hey todd, what do you think about the solution I proposed?

It's ok?

todd_Author Commented:
That's perfect, I'm sorry it took so long for me to reply as I kind of lost hope after I replied.. thanks.. all points to you :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.