473,396 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Small syntax question

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
4 924
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Alont | last post by:
I'm using EDITPLUS now, but this editor really stupid for writing and testing ASP code, I emphasize "small" is because of I'm using 32K MODEM, I can't online too long time or I'll pay much money...
1
by: Gena | last post by:
Hi , I'm a newbe to programming and have a small question: I made a small program with a class. in the class's header file I have : double *ptr_output; Void main() { double result;
32
by: David Isaac | last post by:
I have no experience with database applications. This database will likely hold only a few hundred items, including both textfiles and binary files. I would like a pure Python solution to the...
1
by: srikar | last post by:
Hi I am having a small query For the class strstream suppose &line be the object of that class If we want to set the class stringstream for input operations Is this syntax is a valid syntax ...
16
by: Bruce W. Darby | last post by:
I've almost completed my little application for work. This weekend I've been working on Streams so I can write a logfile showing the work that was accomplished. Wanting to make each logfile...
0
by: NM | last post by:
Hello, I've got a problem inserting binary objects into the postgres database. I have binary objects (e.g. images or smth else) of any size which I want to insert into the database. Funny is it...
169
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide...
6
by: Bill Cunningham | last post by:
As I have been studing my tutorial I came up with this question. I took char passw(char name); and initialied this function in a header with other includes for standard library headers. This...
16
by: scholz.lothar | last post by:
I want to add some extension features to my program and this would require that i bundle a small c compiler with my program. On Unix it seems that tiny-c can do this, but i don't know about windows.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.