> How come something like this is not legal?
>
[quoted text clipped - 18 lines]
> 'System.IO.BinaryWriter.Write(bool)' has some invalid arguments
> C:\code\Form1.cs 90 13 File1
Indeed. Which overload did you expect to use?
> Error 2 Argument '1': cannot convert from 'File1.Form1.NodeRec' to 'bool'
> C:\code\Form1.cs 90 27 File1
>
> I am assuming that I have to add one value at a time to the writer (which
> works), then write it out to the stream instead of just trying to write
> the class to the stream.
Well, an alternative is to use one of the serializers -
BinarySerializer or XmlSerializer, for instance.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
John Rogers - 07 Mar 2008 21:09 GMT
I have never used serialization before so I did not know about it. Even
after
reading about it I still can't get it to work.
In some of the other languages you have like an ItemData property. In c#
I am trying to attain the same kind of functionality, but so far I am not
getting
anywhere with it. I read a bit on serializing data, but I couldn't find any
good
examples to really show me how to use it in mycase.
String DATFILE = szPath + "\\Test.dat";
fStream = new FileStream(FILE_NAME, FileMode.Create);
binWriter = new BinaryWriter(fStream);
LoopingFunctionToGetMyData();
binWriter.Close();
public class myRec
{
public string Name = "";
public string Address = "";
public bool Update = false;
}
myRec mRec = new myRec();
mRec.Name = data.name;
mRec.Address = data.address;
mRec.Update = data.update;
// outStream.Write(mRec);
BinaryFormatter binFormatter = new BinaryFormatter();
binFormatter.Serialize(fStream, myRec);
I can't get past this, because I am looping over 100 times and filling my
class with the info
I need. Apparently my serialize os not working.
Can you show me an example or fill in the blanks of what I am missing.
Thanks
John
>> How come something like this is not legal?
>>
[quoted text clipped - 30 lines]
> Well, an alternative is to use one of the serializers -
> BinarySerializer or XmlSerializer, for instance.
Jon Skeet [C# MVP] - 08 Mar 2008 19:25 GMT
> I have never used serialization before so I did not know about it. Even
> after reading about it I still can't get it to work.
Well, what's happening when you try?
Could you post a short but *complete* program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
>How come something like this is not legal?
>
[quoted text clipped - 28 lines]
>
>John
The BinaryFormatter class is what you're looking for.

Signature
Posted via a free Usenet account from http://www.teranews.com
> How come something like this is not legal?
>
[quoted text clipped - 28 lines]
>
> John
This is a code snip to save and retrieve data of class. Using erialization:
CustomerInfo customer = new CustomerInfo();
customer.Age = 20;
customer.Name = "Kate Moss";
using (System.IO.Stream outStream = IO.File.Create(@"c:\file.data"))
{
System.Runtime.Serialization.IFormatter formater = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
formater.Serialize(outStream, customer);
}
using (System.IO.Stream outStream =
System.IO.File.OpenRead(@"c:\file.data"))
{
System.Runtime.Serialization.IFormatter formater = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
customer = formater.Deserialize(outStream) as CustomerInfo;
}
class CustomerInfo
{
string _name;
int age;
public string Name
{
get { return _name; }
set { _name = value; }
}
public int Age
{
get { return age; }
set { age = value; }
}
}
Hope this help.

Signature
Thanks,
Duy Lam Phuong
John Rogers - 09 Mar 2008 15:39 GMT
Appreciate it Duy.
> This is a code snip to save and retrieve data of class. Using
> erialization:
[quoted text clipped - 3 lines]
> customer.Name = "Kate Moss";
> using (System.IO.Stream outStream = IO.File.Create(@"c:\file.data"))