Solved

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

Posted on 2011-09-04
1
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

632 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