I guess what I want to do is best explain via the codes here;
Byte[] byteA = new Byte[100000];
Byte[] byteB = new Byte[4];
....
....
....
Now I want to copy 4 bytes from certain portion of the byteA array.
In C/C++, this is what we do;
memcpy(byteB, byteA[X], 4);
Or
memcpy(byteB, byteA+X, 4);
But with C#, I had been stuck for a while with no luck....
Hope you understand what I wanted and could show me the way.
Thanks for your time. Sometime I wish Microsoft could create C# to be nearer
to C/C++. C# is still driving me headache... 6 36176
You can either use one of the overloads of the Array.Copy method, or
Buffer.BlockCopy. MSDN online has all the details and method signatures plus
sample code.
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"EOS" wrote: I guess what I want to do is best explain via the codes here;
Byte[] byteA = new Byte[100000]; Byte[] byteB = new Byte[4]; .... .... ....
Now I want to copy 4 bytes from certain portion of the byteA array.
In C/C++, this is what we do;
memcpy(byteB, byteA[X], 4);
Or
memcpy(byteB, byteA+X, 4);
But with C#, I had been stuck for a while with no luck....
Hope you understand what I wanted and could show me the way.
Thanks for your time. Sometime I wish Microsoft could create C# to be nearer to C/C++. C# is still driving me headache...
"EOS" <no****@nospam.org> wrote in
news:O7**************@TK2MSFTNGP09.phx.gbl: I guess what I want to do is best explain via the codes here;
Byte[] byteA = new Byte[100000]; Byte[] byteB = new Byte[4]; ... ... ...
Now I want to copy 4 bytes from certain portion of the byteA array.
In C/C++, this is what we do;
memcpy(byteB, byteA[X], 4);
Or
memcpy(byteB, byteA+X, 4);
But with C#, I had been stuck for a while with no luck....
Hope you understand what I wanted and could show me the way.
Thanks for your time. Sometime I wish Microsoft could create C# to be nearer to C/C++. C# is still driving me headache...
When looking for a method in .Net, first think about what type you
are dealing with. Then look at that type's methods to see if it has
the functionality you desire.
In your case, you are dealing with the System.Array type. It has a
static Copy method that will do what you want:
System.Array.Copy(byteA, 0, byteB, 0, 4);
--
Hope this helps.
Chris.
-------------
C.R. Timmons Consulting, Inc. http://www.crtimmonsinc.com/
Ok... Understood and I will avoid that in the future.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... EOS <no****@nospam.org> wrote: I guess what I want to do is best explain via the codes here;
Please see my response in the framework group. Multi-posting questions is a bad idea in general - it wastes people's time, as people will respond in one group without seeing that you've already got an anser in another group.
See http://www.pobox.com/~skeet/csharp/faq/posting.html
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too
In .NET 2.0 Buffer.BlockCopy is implemented in with the help of unsafe
functions the source looks like classical memcpy :8-)
--
Vadym Stetsyak aka Vadmyst http://vadmyst.blogspot.com
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:02**********************************@microsof t.com... You can either use one of the overloads of the Array.Copy method, or Buffer.BlockCopy. MSDN online has all the details and method signatures plus sample code. Peter -- Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com
"EOS" wrote:
I guess what I want to do is best explain via the codes here;
Byte[] byteA = new Byte[100000]; Byte[] byteB = new Byte[4]; .... .... ....
Now I want to copy 4 bytes from certain portion of the byteA array.
In C/C++, this is what we do;
memcpy(byteB, byteA[X], 4);
Or
memcpy(byteB, byteA+X, 4);
But with C#, I had been stuck for a while with no luck....
Hope you understand what I wanted and could show me the way.
Thanks for your time. Sometime I wish Microsoft could create C# to be nearer to C/C++. C# is still driving me headache...
Excuss me, what's wrong with clasical memcpy? I had been using it for my
whole life for C/C++ development and I love it and miss it now C# : (
"Vadym Stetsyak" <va*****@ukr.net> wrote in message
news:en***************@TK2MSFTNGP11.phx.gbl... In .NET 2.0 Buffer.BlockCopy is implemented in with the help of unsafe functions the source looks like classical memcpy :8-)
-- Vadym Stetsyak aka Vadmyst http://vadmyst.blogspot.com
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message news:02**********************************@microsof t.com... You can either use one of the overloads of the Array.Copy method, or Buffer.BlockCopy. MSDN online has all the details and method signatures plus sample code. Peter -- Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com
"EOS" wrote:
I guess what I want to do is best explain via the codes here;
Byte[] byteA = new Byte[100000]; Byte[] byteB = new Byte[4]; .... .... ....
Now I want to copy 4 bytes from certain portion of the byteA array.
In C/C++, this is what we do;
memcpy(byteB, byteA[X], 4);
Or
memcpy(byteB, byteA+X, 4);
But with C#, I had been stuck for a while with no luck....
Hope you understand what I wanted and could show me the way.
Thanks for your time. Sometime I wish Microsoft could create C# to be nearer to C/C++. C# is still driving me headache...
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Vince |
last post by:
Hi,
I have replaced my BYTE* by a vector<BYTE> and before I used to do :
void CCardRecord::GetRecData(int nOffset, int nDataSize, CString& csValue)
{
BYTE *pTmp = NULL;
pTmp = new BYTE;...
|
by: Khuong Dinh Pham |
last post by:
I have the contents of an image of type std::string. How can I make a
CxImage object with this type.
The parameters to CxImage is:
CxImage(byte* data, DWORD size)
Thx in advance
|
by: Case |
last post by:
#include <string.h>
int i; /* 4-byte == 4-char */
char data = { 0x78, 0x56, 0x34, 0x12 };
int main()
{
memcpy(&i, data, 4);
/*
|
by: babylon |
last post by:
i have a byte array
e.g.
byte abc = new byte;
and i have some integers
e.g.
int height = 166;
int age = 23;
i wanna store them into the byte array abc like ""
|
by: Eric |
last post by:
Tell me why the following doesn't work...
void MyClass::StoreCommand( struct command cmdToStore )
{
memcpy( (char*)&theCommand,
(char*)&cmdToStore,
sizeof( struct command ) );
}
theCommand...
|
by: Mark |
last post by:
Hi List,
I want to write a function to copy some data out of a hardware buffer.
The hardware can change the contents of this buffer without it being
written to by my function. I want to use...
|
by: Ashit Vora |
last post by:
Hi,
I had one small query.
I have a data in char pointer (actually 4 char pointers)
I wanna make one char pointer out of it (without terminating it with
NULL. so cant use STRCPY).
I used...
|
by: Andrew Poelstra |
last post by:
On Thu, 2008-09-04 at 12:05 -0700, Ashit Vora wrote:
No, if anything you have an address in a char pointer (or
four addresses in four pointers).
What does this mean? I'm going to assume you...
|
by: Ashit Vora |
last post by:
Hi,
I had one small query.
I 'm coping data from an unsigned short to a char*.
code is
#include<stdio.h>
int main(void){
unsigned short type=0xFE10;
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
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...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
|
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...
|
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,...
| |