By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,714 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,714 IT Pros & Developers. It's quick & easy.

Small syntax question

P: n/a
Hi,

I'm not expert with C# (I'm more with Java and C++). I have to work
with an existing C# code. And I have a question about this lines :

...
TCP_DATAHEADER buffer = (TCP_DATAHEADER) asyncState.buffer;
Array.Copy(asyncState.buffer, buffer.cbHeader, asyncState.buffer,
0, buffer.dwBytes - buffer.cbHeader);
string dwType = buffer.dwType;
...

What does the first line do ? A simple cast or a copy ? I think it is
a copy, because the line 2 make a copy overwriting the initiale data,
and the line 3 seems to asses to this original data ...

But I'm not sure, it's strange ...

Thanks,

Xavier

Sep 24 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Sep 24, 9:04*am, Zaza <xno...@hotmail.comwrote:
I'm not expert with C# (I'm more with Java and C++). I have to work
with an existing C# code. And I have a question about this lines :

* * ...
* * TCP_DATAHEADER buffer = (TCP_DATAHEADER) asyncState.buffer;
* * Array.Copy(asyncState.buffer, buffer.cbHeader, asyncState.buffer,
0, buffer.dwBytes - buffer.cbHeader);
* * string dwType = buffer.dwType;
* * ...

What does the first line do ? A simple cast or a copy ? I think it is
a copy, because the line 2 make a copy overwriting the initiale data,
and the line 3 seems to asses to this original data ...
We can't really tell without knowing what TCP_DATAHEADER looks like,
or what asyncState.buffer is.

Jon

Sep 24 '08 #2

P: n/a
Hi Jon,
We can't really tell without knowing what TCP_DATAHEADER looks like,
or what asyncState.buffer is.
You're right !

Oups, sorry ! I just see this line in TCP_DATAHEADER :

public static explicit operator TCP_DATAHEADER(byte[] data);

I supposed it's like in C++, and this explain the line 1 in my sample
that is not a cast but a call to this operator (that make a copy of
the data).

Thank your for your reply,

Xavier
Sep 24 '08 #3

P: n/a
On Sep 24, 2:03*pm, Zaza <xno...@hotmail.comwrote:
We can't really tell without knowing what TCP_DATAHEADER looks like,
or what asyncState.buffer is.

You're right !

Oups, sorry ! I just see this line in TCP_DATAHEADER :

* * public static explicit operator TCP_DATAHEADER(byte[] data);

I supposed it's like in C++, and this explain the line 1 in my sample
that is not a cast but a call to this operator (that make a copy of
the data).
Right. Do you have control over this type? If so, I'd get rid of the
operator and create a method FromBytes or something like that - it'll
be a lot clearer.

Jon
Sep 24 '08 #4

P: n/a
Hi Jon,

In fact, I am writing Java code for a TCP/IP protocol, and the only
documentation I have is C# code, that I have to understand.

I hav'nt to touch or change this C# code. I aggree with you, this code
is a little ambiguous ... ;-)

Thank you for your help,

Xavier
Sep 26 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.