Solved

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

Posted on 2011-09-04
1
299 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now