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

  • Home
  • SEARCH
  • 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 8109427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:24:58+00:00 2026-06-06T01:24:58+00:00

I have a set of string that I need to store in a set,

  • 0

I have a set of string that I need to store in a set, such as:

id, firstname, lastname, city, country, language

All of the above apply to a single person (represented by the ID)

Now I have 60 – 70 of these (and growing), how could I organize them? I have looked at the NameValueCollection class – and it does exactly what I want (if I only had two fields), but since I have 6 fields, I can’t use it. E.g.:

public NameValueCollection personCollection = new NameValueCollection
    {
        { "harry", "townsend", "london", "UK", "english" },
        { "john", "cowen", "liverpool", "UK", "english" },
        // and so on...
    };

Although this does not work 🙁 Could someone suggest another way of achieving this?

  • 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-06T01:25:00+00:00Added an answer on June 6, 2026 at 1:25 am

    If you absolutely don’t want to create any new classes, you could use a dictionary of lists, keyed by your ID:

    IDictionary<string, IList<string>> personCollection =
        new Dictionary<string, IList<string>>
    {
        { "1", new [] { "harry", "townsend", "london", "UK", "english" }},
        { "2", new [] { "john", "cowen", "liverpool", "UK", "english" }},
    };
    

    …which you could then access using dictionary and list indexers:

    Console.WriteLine(personCollection["1"][0]);   // Output: "harry"
    Console.WriteLine(personCollection["2"][2]);   // Output: "liverpool"
    

    However, the correct OOP approach would be to define a class with properties for your respective strings:

    public class Person
    {
        public string Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string City { get; set; }
        public string Country { get; set; }
        public string Language { get; set; }
    
        public Person() { }
    
        public Person(string id, string firstName, string lastName, 
                      string city, string country, string language)
        {
            this.Id = id;
            this.FirstName = firstName;
            this.LastName = lastName;
            this.City = city;
            this.Country = country;
            this.Language = language;
        }
    }
    

    You could then create a list of persons:

    IList<Person> persons = new List<Person>()
    {
        new Person("1", "harry", "townsend", "london", "UK", "english"),
        new Person("2", "john", "cowen", "liverpool", "UK", "english"),
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a c# class that has 20+ string properties. I set about a
I have set adapter to the MultiAutoCompleteTextView in my android application. ArrayAdapter<String> adapter =
I have been facing issue with sphinx result set for string attribute. Below is
I have a set of sql - queries: List<String> queries = ... queries[0] =
I have a SqlDependency set up using the following query: string sql = "SELECT
I have a variable, emailBody, which is set to a string stored in a
I have the following code set up in my Startup IDictionary<string, string> properties =
I have the following class public class UIControl { public string FName{ get; set;
Say you have a string 3.4564. A sample set in the database has these
I have the following code: private static final Set<String> allowedParameters; static { Set<String> tmpSet

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.