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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:21:04+00:00 2026-06-18T23:21:04+00:00

I retrieved a list of users from database, something like List<User> users = <..list

  • 0

I retrieved a list of users from database, something like

List<User> users = <..list of users from db...> 

Name, LastName, DateOfBirth //multidimensional array??

Now I want to store this list as a string and I want be able to reuse it i.e.

string strUsers = users.ToArray().ToString();

How to recreate a list of users from strUsers?

Is it possible?

  • 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-18T23:21:06+00:00Added an answer on June 18, 2026 at 11:21 pm

    If you have a lot of users and a lot of columns, it would be better to write your own custom converter class.

    public static class UsersConverter
    {
        // Separates user properties.
        private const char UserDataSeparator = ',';
    
        // Separates users in the list.
        private const char UsersSeparator = ';';
    
        public static string ConvertListToString(IEnumerable<User> usersList)
        {
            var stringBuilder = new StringBuilder();
    
            // Build the users string.
            foreach (User user in usersList)
            {
                stringBuilder.Append(user.Name);
                stringBuilder.Append(UserDataSeparator);
                stringBuilder.Append(user.Age);
                stringBuilder.Append(UsersSeparator);
            }
    
            // Remove trailing separator.
            stringBuilder.Remove(stringBuilder.Length - 1, 1);
    
            return stringBuilder.ToString();
        }
    
        public static List<User> ParseStringToList(string usersString)
        {
            // Check that passed argument is not null.
            if (usersString == null) throw new ArgumentNullException("usersString");
    
            var result = new List<User>();
    
            string[] userDatas = usersString.Split(UsersSeparator);
    
            foreach (string[] userData in userDatas.Select(x => x.Split(UserDataSeparator)))
            {
                // Check that user data contains enough arguments.
                if (userData.Length < 2) throw new ArgumentException("Users string contains invalid data.");
    
                string name = userData[0];
                int age;
    
                // Try parsing age.
                if (!int.TryParse(userData[1], out age))
                {
                    throw new ArgumentException("Users string contains invalid data.");
                }
    
                // Add to result list.
                result.Add(new User { Name = name, Age = age });
            }
    
            return result;
        }
    }
    

    You will win performance wise using the StringBuilder to build up your users string. You could also easily expand the converter to take account different separators/additional logic etc.

    If you need a more generic solution (to be able to use for any class), you could create a converter which uses reflection to iterate over all the public fields, get/set properties to see what can be extracted as string and later reverse the process to convert your string back to the list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I populate web form with dynamic list of exams from database. I want user
I want to display the data retrieved from the JSP page in my List.
I'm trying to generate a list dynamically from database. The results can be retrieved,
I have a list of books obtained from the database. When a user selects
I have a list of photos retrieved from database and displayed on the html.
I want to retrieve a list of people's names from a queue and, for
I have a Jquery Function that basically retrieves a list of users from the
Greetings fellow earthlings. I'm researching methods of caching data retrieved from various database tables
I have a listView which loads data from SQLite database and right now I
I have an app where I retrieve a list of users from a specific

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.