Click here to Skip to main content
15,923,142 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
It's easy to do something like this
foreach(Grade curr in arrList)
{
     myStreamWriter.Write(Grade.Name);
     myStreamWriter.Write(Grade.Score);
}

Is there an easy method to read/write all the Grade object?

Edit
====

Of course the example should have been curr.property
but I am looking for a way to write all the curr at once
Posted
Updated 10-Dec-11 6:27am
v2

Your attempt was a naive way. The best, most universal, easiest and non-intrusive way is using Data Contract.

Please see http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

Please also see my past answers where I advocate this wonderful approach and explain some important detail:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^],
deseralize a json string array[^].

—SA
 
Share this answer
 
Comments
Wonde Tadesse 9-Dec-11 17:42pm    
5+
Sergey Alexandrovich Kryukov 10-Dec-11 15:50pm    
Thank you, Wonde. Did you forget to vote though?
--SA
Wonde Tadesse 10-Dec-11 17:30pm    
Opps.I thought I did it.How about now!
Sergey Alexandrovich Kryukov 10-Dec-11 18:45pm    
Appreciate it!
--SA
Monjurul Habib 10-Dec-11 15:32pm    
5!
Try to use different object serialization technique. Here are lists of MSDN articles.
1. DataContract Serializer [^]
2. How to serialize an object to XML by using Visual C#[^]
3. Walkthrough: Persisting an Object[^]
 
Share this answer
 
v2
Comments
Monjurul Habib 10-Dec-11 15:33pm    
5!
Wonde Tadesse 10-Dec-11 17:29pm    
Thanks
Sergey Alexandrovich Kryukov 10-Dec-11 15:53pm    
I think using of this kind of serialization for custom purposes is rendered obsolete by the Data Contact.
--SA
Easy is a relative term. What are you trying to accomplish? Simply your code, improve performance?

You could make sure the objects are serializable then serialize them to some file stream, but the method you have is simple enough.
 
Share this answer
 
Comments
Member 7966831 9-Dec-11 11:51am    
I try to write in a single row like is available in C++
Wonde Tadesse 9-Dec-11 17:42pm    
5+
It's easy to do something like this
Collapse | Copy Code
C#
foreach(Grade curr in arrList)
{
     myStreamWriter.Write(Grade.Name);
     myStreamWriter.Write(Grade.Score);
}

Is there an easy method to read/write all the Grade object?



The 2 easy looks contradicting. What are you really trying to say?

-Eduard
 
Share this answer
 
Comments
Member 7966831 10-Dec-11 12:15pm    
I am trying to write/read all the object, without carring of the properties.
Something like mySWriter.Write(grade1);
[no name] 11-Dec-11 6:48am    
did you mean you need to get all the properties of an object?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900