Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3496192
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:13:06+00:00 2026-05-18T12:13:06+00:00

I have several collections of classes/structs in my app. The class is just a

  • 0

I have several collections of classes/structs in my app.

The class is just a class with fields

class A
{
  public int somevalue;
  public string someothervalue
}

And my collection

List<A> _myList;

I need to be able to save _myList and load. I just want to save all class fields to file and load. I don’t want to spend time writing my own save/load. Are there any tools in .NET to help me. I don’t care about the file format.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:13:07+00:00Added an answer on May 18, 2026 at 12:13 pm

    XMLSerializer isn’t hard to use. As long as your objects aren’t huge, it’s pretty quick. I serialize out some huge objects in a few of my apps. It takes forever and the resulting files are almost 100 megs, but they’re editable should I need to tweak some stuff. Plus it doesn’t matter if I add fields to my objects. The serialized files of the older version of the object still deserialize properly.. I do the serialization on a separate thread so it doesn’t matter how long it takes in my case. The caveat is that your A class has to have a constructor for XMLSerialziation to work.

    Here’s some working code I use to serialize/deserialize with the error handling ripped out for readibility…

    private List<A> Load()
    {
        string file = "filepath";
        List<A> listofa = new List<A>();
        XmlSerializer formatter = new XmlSerializer(A.GetType());
        FileStream aFile = new FileStream(file, FileMode.Open);
        byte[] buffer = new byte[aFile.Length];
        aFile.Read(buffer, 0, (int)aFile.Length);
        MemoryStream stream = new MemoryStream(buffer);
        return (List<A>)formatter.Deserialize(stream);
    }
    
    
    private void Save(List<A> listofa)
    {
        string path = "filepath";
        FileStream outFile = File.Create(path);
        XmlSerializer formatter = new XmlSerializer(A.GetType());
        formatter.Serialize(outFile, listofa);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have several ObservableCollections of different classes: public class Employee { public int
I have several classes, and want to work with their collections like with a
I have a class TContainer that is an aggregate of several stl collections pointers
I have written my Container<T> class which backups its T items in several collections
What I'm trying to do is fairly simple. I have two classes: public class
Say I have several derived classes whose base class is a generic class. Each
I have a collection that contains instances of several different classes, and I want
I have several collections to be fetched on page load. Every collection depends on
I have these classes public class CoffeeUser { public CoffeeUser() { DrinkedCoffees = new
I have an the following scenario: // several classes that implement different interfaces class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.