|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to return the pointer of int32 in C# .NET?I am a bit shocked that C# got nothing to do with C/C++. Here is what I wanted to do; Int32 f_nSomeValue = 200; // Supposed to be 4 bytes long in length, right? MemoryStream f_MemoryStream = new MemoryStream(20); f_MemoryStream.Write(&f_nSomeValue, 0 , 4); The first param of the MemoryStream is expecting byte[ ]. I tried to cast it but the complier would not let me to continue. Does anyone know how do I convert the int32 so that it is can be used on the MemoryStrem.Write( )? Thanks for reading.
Show quote
Hide quote
"Gravity" <gravity@nospam.org> wrote in message Try this:news:u97lkNqaFHA.1152@tk2msftngp13.phx.gbl... > Hi, > > I am a bit shocked that C# got nothing to do with C/C++. > > Here is what I wanted to do; > Int32 f_nSomeValue = 200; // Supposed to be 4 bytes long in length, > right? > > MemoryStream f_MemoryStream = new MemoryStream(20); > > > f_MemoryStream.Write(&f_nSomeValue, 0 , 4); > > The first param of the MemoryStream is expecting byte[ ]. I tried to cast > it but the complier would not let me to continue. f_MemoryStream.Write(BitConverter.GetBytes(f_nSomeValue), 0 , 4); Best regards, Jeroen Vandezande Thanks for the quick reply. It works.
After learning C#, I hope I do not confuss with my current C/C++. There are just so much differences. Show quoteHide quote "Jeroen Vandezande" <nospam@nospam.spam> wrote in message news:et$yh4qaFHA.1384@TK2MSFTNGP09.phx.gbl... > > "Gravity" <gravity@nospam.org> wrote in message > news:u97lkNqaFHA.1152@tk2msftngp13.phx.gbl... >> Hi, >> >> I am a bit shocked that C# got nothing to do with C/C++. >> >> Here is what I wanted to do; >> Int32 f_nSomeValue = 200; // Supposed to be 4 bytes long in length, >> right? >> >> MemoryStream f_MemoryStream = new MemoryStream(20); >> >> >> f_MemoryStream.Write(&f_nSomeValue, 0 , 4); >> >> The first param of the MemoryStream is expecting byte[ ]. I tried to cast >> it but the complier would not let me to continue. > > > Try this: > > f_MemoryStream.Write(BitConverter.GetBytes(f_nSomeValue), 0 , 4); > > > Best regards, > > Jeroen Vandezande > > "Gravity" <gravity@nospam.org> wrote in message Yeah I know...news:OOBcueraFHA.1384@TK2MSFTNGP09.phx.gbl... > Thanks for the quick reply. It works. > > After learning C#, I hope I do not confuss with my current C/C++. There > are just so much differences. I also had to learn it the hard way... I come from delphi. The trick is: If want to do something.. the chance is that there is a function inside the .net framework to do it... If you want to do low level bytemanipulations... take a good look at the Bitconvertor Class... It's priceless. Best Regards, Jeroen Vandezande.
Other interesting topics
A challenge to all MVP's.......GET A J.O.B. for once in your life
How to do simple memcpy in C#? Text Files, Encoding and NewLine character Read File Fast Self populating collection Enable a windows form over another one? Implementing an interface by relying on base class MSCORCFG Save a System.Drawing.Color in the db HOW TO CONNECT TO SQL SERVER 2000 DATABASE |
|||||||||||||||||||||||