Solved

How to pass an explicit array of bytes as a byte array

Posted on 2011-09-04
1
303 Views
Last Modified: 2012-05-12
I have a method that accepts a byte array as a parameter:
    private void mymsg(byte[] barray)
    {
      ...
    }

Open in new window

which I currently call:
      byte[] n = { 0x35, 0x04 };
      mymsg( n );

Open in new window

I'd like to call it in one step instead of two. Something like this (but without the syntax errors)
   mymsg( { 0x35, 0x04 } );

Open in new window

What's the proper syntax for this?
0
Comment
Question by:deleyd
1 Comment
 
LVL 17

Accepted Solution

by:
andrewssd3 earned 500 total points
ID: 36481323
I think the syntax you're looking for is

mymsg(new byte[]{ 0x35, 0x04 });

Open in new window


although I'm not sure it makes much difference, except saving a line!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question