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 9255285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:40:59+00:00 2026-06-18T11:40:59+00:00

In my app I am writing data into a text file by converting a

  • 0

In my app I am writing data into a text file by converting a list into an array, later on I want to load it by converting it to the same list type and return it like that.

My code:

public abstract class PhoneBookCore
{
    protected string _group;

    public PhoneBookCore(string group)
    {
        this._group = group;
    }
}

public class Group : PhoneBookCore
{
    private List<PhoneBookCore> elements = new List<PhoneBookCore>();

    public List<PhoneBookCore> elementsList { 
         get { return new List<PhoneBookCore>(elements); } 
    }

    public Group(string name)
        : base(name)
    {
    }

class DataOptions
{
    public void Save(Group g)
    {
        string[] lines = g.elementsList.ConvertAll(p => p.ToString()).ToArray();
        File.WriteAllLines(path, lines);
    }

    public Group Load()
    {
        string[] buffer = File.ReadAllLines(path); // ----> How do I convert it back
                                                   //       to list of type group?

        return ;
    }
}  

How do I convert it back to list of type group?

  • 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-06-18T11:41:01+00:00Added an answer on June 18, 2026 at 11:41 am

    Maybe (assuming that you want to pass the whole line to the Group-constructor)

    List<Group> allgroups = File.ReadLines(path)   
        .Select(l => new Group(l))
        .ToList();
    

    Note that I’ve used File.ReadLines which returns a streaming IEnumerable<string> instead of a string[], you can also read all into memory at once with File.ReadAllLines.

    But why do you always create a new list in the elementsList property? Just return elements.

    Edit If you want to create one group and set the elementsList from the lines, you need to provide the setter of the property first:

    private List<PhoneBookCore> _elementsList = new List<PhoneBookCore>();
    public List<PhoneBookCore> ElementsList
    { 
        get { return _elementsList; }
        set { _elementsList = value; }
    }
    

    Then you can initialize and set the group on this way:

    Group g = new Group(path); // i have no idea
    g.ElementsList = File.ReadLines(path)
        .Select(l => new PhoneBookCore(l))
        .ToList();
    
    return g;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing my first comprehensive app using Core Data, and I want to
I am writing an android app. I want to pass some data across the
I am writing to the text file some data. I am using this code:
I'm writing a c# app that inserts a large (1GB+) amount of data into
I'm writing a latency-sensitive app which reads a text file upon initialisation. I have
I am writing an app that requires the user to enter some data into
I'm writing an App and an accopmanying widget that needs data. This data is
I'm writing an app that is calling a server to get data to show
I'm writing an app where I need to associate data with user pairs. For
I'm writing an iOS app which utilizes Core Data (NSManagedObject, NSManagedObjectContext..etc) and I was

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.