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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:48:27+00:00 2026-05-31T09:48:27+00:00

This is a follow up question from another post but that post was answered.

  • 0

This is a follow up question from another post but that post was answered. I have a for loop that I want to add three items to a generic class and I’m not sure how to do that. How do I add those items?

private static void TestResults()
{
    List<Record> Records = new List<Record>();

    for (int i = 0; i < ProxyList.Count; i++)
    {
        string[] split = List[i].Split('|');
        // This is what i dont know how to do
        //  split[0] = Name, split[1] = SomeValue and split[3] = OrderNr
    }
}

class Records
{
    public static string Name { get; set; }
    public static int SomeValue { get; set; }
    public static int OrderNr { get; set; }
}
  • 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-31T09:48:28+00:00Added an answer on May 31, 2026 at 9:48 am

    Well for one thing, your properties must not be static. You want different data for each instance, right? So they need to be instance properties. Personally I’d also make the type immutable, but that’s another matter:

    class Record // Changed from Records; each object is only a single record...
    {
        public string Name { get; set; }
        public int SomeValue { get; set; }
        public int OrderNumber { get; set; }
    }
    
    private static List<Record> ConvertRecords(IEnumerable<string> lines)
    {
        List<Record> records = new List<Record>();
    
        foreach (string line in lines)
        {
            string[] split = line.Split('|');
            Record record = new Record {
                Name = split[0],
                SomeValue = int.Parse(split[1]),
                OrderNumber = int.Parse(split[2]);
            };
            records.Add(record);
        }
    }
    

    As of C# 3 / .NET 3.5, a more idiomatic approach would be to use LINQ:

    private static List<Record> ConvertRecords(IEnumerable<string> lines)
    {
        return (from line in lines
                let split = line.Split('|')
                select new Record {
                    Name = split[0],
                    SomeValue = int.Parse(split[1]),
                    OrderNumber = int.Parse(split[2]);
                }).ToList();
        }
    }
    

    … on the other hand, that’s relatively advanced if you’re really just starting to learn the language.

    To be honest, Stack Overflow is better for asking specific questions than structured learning – I suggest you get hold of a good book, such as C# 4 in a Nutshell.

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

Sidebar

Related Questions

This is a follow up from a question of mine that was just answered
This is a follow on from another question i made I have this query
this kind of follows on from another question of mine. Basically, once I have
This is a follow-up to my question from yesterday . I have Scott Meyers'
This question is a follow-up from How to indicate that a method was unsuccessful
This is a follow up question from Problem with array assignment I now have
This is a follow on from another question, my question is regarding the use
This is a follow-up question to another SO question of mine . I have
I have a number of xml files that should follow this format: <root> <question>What
This is a follow up of another question here on SO . I have

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.