C# syntax question

  • Thread starter Thread starter Sid Price
  • Start date Start date
S

Sid Price

HI,

Although I am an experienced C++ programmer I am relatively new to C#. I
have a method that has the following prototype:

public int GetDataBytes(ref byte[] dataBuf, int numBytes)

The calling code has a byte buffer defined but I need to pass a reference to
a point that is offset in that buffer.

What is the syntax for doing this?

In C I would have done:

byte buffer[32] ;

GetDataBytes(&buffer[20],5) ;

Thank you,
Sid.
 
What is the syntax for doing this?

C# doesn't let you do that. Pass the starting index as a separate
parameter instead.

If GetDataBytes simply populates an existing array, there's no need
for making the first parameter a ref parameter.


Mattias
 
Thank you Mattias that is what I have implemented and now my code compiles
and works as expected,
Sid.
 
Back
Top