Click here to Skip to main content
15,895,142 members
Home / Discussions / C#
   

C#

 
GeneralRe: Generic Hashtable Pin
Marc Clifton2-May-05 10:53
mvaMarc Clifton2-May-05 10:53 
GeneralRe: Generic Hashtable Pin
Anonymous3-May-05 5:09
Anonymous3-May-05 5:09 
GeneralRe: Generic Hashtable Pin
leppie2-May-05 14:46
leppie2-May-05 14:46 
GeneralOle Server Pin
BigAnyon2-May-05 5:58
BigAnyon2-May-05 5:58 
GeneralVisual style icons / bitmaps Pin
Anonymous2-May-05 5:45
Anonymous2-May-05 5:45 
GeneralRe: Visual style icons / bitmaps Pin
Judah Gabriel Himango2-May-05 7:05
sponsorJudah Gabriel Himango2-May-05 7:05 
GeneralRe: Visual style icons / bitmaps Pin
MoustafaS2-May-05 8:49
MoustafaS2-May-05 8:49 
GeneralEasy file I/O Pin
briggs_w2-May-05 4:58
briggs_w2-May-05 4:58 
In C++, I could read/write an object thus:

read ((void*) &myObject, 0, sizeof (Object)); //same for write

...rather than having to write a function that read/writes each individual field in the object. Can this be done in C#? My attempt gives me a problem with the &myObject: "can't take the address of a managed class."

If not, can this be done some other way?

If not . . . my alternate in C++ would be

istream& operator>> (istream& in, myClass& myObject)
{
return in >> field1 >> field2 >> ...;
}

The closest I can come in C# is

public void Read (Stream s)
{
s.ReadBool (field1);
field2.Read (s); //if field2 is of a class that I wrote
for (int i = 0; i < DimensionIHaveToRemember1; ++i)
for (int j = 0; j < DimensionIHaveToRemember2; ++j)
s.ReadInt (field3[i,j]);
...
}

(assuming
bool field1;
someClass field2;
int [,] field3; //OK, I'd have to do something special
//to make C++ do this easily, too...
...)

...and this seems needlessly messy. Is there a better way?

Thanks -- and if you want to refer me to a book, fine: C# and the .NET platform by Troelson is what I'm using, and it doesn't answer these questions, but maybe another does.
GeneralRe: Easy file I/O Pin
Heath Stewart2-May-05 5:11
protectorHeath Stewart2-May-05 5:11 
GeneralRe: Easy file I/O Pin
Marc Clifton2-May-05 5:24
mvaMarc Clifton2-May-05 5:24 
General... also ... Pin
Marc Clifton2-May-05 5:26
mvaMarc Clifton2-May-05 5:26 
GeneralRe: Easy file I/O Pin
briggs_w5-May-05 5:50
briggs_w5-May-05 5:50 
GeneralAccess a flat file at http location Pin
mrinmayeek2-May-05 4:27
mrinmayeek2-May-05 4:27 
GeneralRe: Access a flat file at http location Pin
Heath Stewart2-May-05 5:12
protectorHeath Stewart2-May-05 5:12 
GeneralControl Instantiation Pin
terrier_jack2-May-05 4:25
terrier_jack2-May-05 4:25 
GeneralRe: Control Instantiation Pin
Marc Clifton2-May-05 5:08
mvaMarc Clifton2-May-05 5:08 
GeneralRe: Control Instantiation Pin
MoustafaS2-May-05 8:54
MoustafaS2-May-05 8:54 
GeneralHTML control Pin
Anonymous2-May-05 3:39
Anonymous2-May-05 3:39 
GeneralRe: HTML control Pin
Heath Stewart2-May-05 5:16
protectorHeath Stewart2-May-05 5:16 
QuestionHow to Connect Managed and UnManaged code for Socket Programming Pin
Shashidharreddy2-May-05 3:08
Shashidharreddy2-May-05 3:08 
AnswerRe: How to Connect Managed and UnManaged code for Socket Programming Pin
S. Senthil Kumar2-May-05 3:51
S. Senthil Kumar2-May-05 3:51 
AnswerRe: How to Connect Managed and UnManaged code for Socket Programming Pin
Dave Kreskowiak2-May-05 4:03
mveDave Kreskowiak2-May-05 4:03 
General.Net Remoting problem Pin
sokettepower2-May-05 2:23
sokettepower2-May-05 2:23 
GeneralRe: .Net Remoting problem Pin
Heath Stewart2-May-05 5:36
protectorHeath Stewart2-May-05 5:36 
GeneralRe: .Net Remoting problem Pin
sokettepower2-May-05 21:37
sokettepower2-May-05 21:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.