Click here to Skip to main content
15,888,271 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a general way to save an object? Specifically, I am using the Aforge DLL to implement neural networks in C#. However I don't see any documentation on how to save a trained neural network so I was wondering if there may be a general way of saving the network to use it later without having to retrain it every time.
Posted

In addition to the BinaryFormatter class advised by Mika, loot at Data Contract. It allows you to store/load not just an object but an arbitrary object graph which does not have to be a tree (hierarchical). Also, this method is very non-intrusive: you don't have to modify your data types in any way, not even access modifiers. All you do is adding attributes to types and members. Also, you can make a very reliable provisions for backup compatibility of your data with newer versions of the applications.

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

See also my past answers where I advocate this wonderful approach:
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
 
v2
Comments
Manfred Rudolf Bihy 29-Dec-11 17:49pm    
Great answer SA! 5+
Sergey Alexandrovich Kryukov 29-Dec-11 20:21pm    
Thank you, Manfred.
--SA
Wendelius 29-Dec-11 17:57pm    
Agree, this is a good solution, as always. 5'ed
Sergey Alexandrovich Kryukov 29-Dec-11 20:21pm    
Thank you, Mika.
--SA
Espen Harlinn 29-Dec-11 18:07pm    
Good suggestion, my 5
Depending on the type of the saved file the mechanism to save an object may vary. Have a look at BinaryFormatter Class[^] for example.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Dec-11 17:42pm    
Agree, my 5, but I always support an alternative -- Data Contract; please see my answer.
--SA
Wendelius 29-Dec-11 17:46pm    
Thanks SA :)
Manfred Rudolf Bihy 29-Dec-11 17:50pm    
Nice solution! 5+
Wendelius 29-Dec-11 17:58pm    
Thanks Manfred :)
Espen Harlinn 29-Dec-11 18:07pm    
Good suggestion, my 5

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