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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:39:10+00:00 2026-06-15T12:39:10+00:00

Input: All the sales data for any given day, extracted from a string by

  • 0

Input: All the sales data for any given day, extracted from a string by the following code:

class Program
{


static void Main(string[] args)
{
    List<Sale> Sales = new List<Sale>();

    // int l = 1;
    using (StreamReader reader = new StreamReader("file.dat"))
    {
        string line;
        var locations = new Dictionary<string, int[]>() {
            {"210", new [] {405, 4, 128, 12, 141, 12, 247, 15, 121, 3}},
            {"310", new [] {321, 4, 112, 12, 125, 12, 230, 15, 105, 3}}, 
            {"410", new [] {477, 4, 112, 12, 125, 12, 360, 15, 105, 3}} 
        };

        while ((line = reader.ReadLine()) != null)
        {


            var lineStart = line.Substring(0, 3);

            if (lineStart == "210" || lineStart == "310" || lineStart == "410")
            {
var currentLocations = locations[lineStart];
                    var letters = line.Substring(currentLocations[0], currentLocations[1]);
                var volume =
                    int.Parse(line.Substring(currentLocations[2], currentLocations[3])) +
                    int.Parse(line.Substring(currentLocations[4], currentLocations[5]));

                var price = long.Parse(line.Substring(currentLocations[6], currentLocations[7]));
                var mvolume = price * volume;
                var currency = line.Substring(currentLocations[8], currentLocations[9]);

This takes the required information I want from the string.

I have a separate class with the same fields as those variables, (but with slightly different names).

public class Sale
    {
        private int CashTotal;
        private string codeletters;
        private string Crncy;
}

further down in my main code I have:

                   Sale s = new Sale();
                   Sales.Add(s);

(this is my full code so far, just broken into parts, it reads from top to bottom as it is in the program – apart from the new class).

What I’m struggling to do at this point is to load the values in each of the var’s into the fields in the class (store Currency as Crncy, mvolume as totalcash, and letters as codeletters), store that object (Sale) into the list (Sales), and then repeat it again. I’m pretty sure there’s a really basic solution for this but I’m stuffed if I can think of it.

edit: Sorry about that, resolved that one and edited the code, accordingly, I’ll show you what I tried which didn’t work but should convey the logic of what I’m trying to do:

                    Sale.CashTotal = mvolume;
                    Sale.Crncy = currency;
                    Sale.codeletters = letters;

I’ve broken down the string into its component parts, but I can only store one object in a list, so i need to recombine them together as a Sale, and store that in the list instead, but getting those values into the Sale is proving to be problematic.

  • 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-15T12:39:10+00:00Added an answer on June 15, 2026 at 12:39 pm

    You’ve declared your fields as private, so they are not accessible out of the class. You can either declare a public constructor and pass the values there. Also you could add publiv properties with only get accessors:

    public class Sale
    {
        private int totalCash;
        public int TotalCash
        {
            get { return totalCash; }
        }
    
        private string codeletters;
        public string Codeletters
        {
            get { return codeletters; }
        }
    
        private string crncy;
        public string Crncy
        {
            get { return crncy; }
        }
    
        public Trade(int _totalCash, string _codeletters, string _crncy)
        {
            totalCash = _totalCash;
            codeletters = _codeletters;
            crncy = _crncy;
        }
    }
    

    This would then be used:

    Sale s = new Sale(mvolume,letters,currency);
    

    Or you could make them public:

        public int TotalCash;
        public string codeletters;
        public string Crncy;
    

    However public fields are definetely bad design, so you’d better make them auto properties:

        public int TotalCash {get; set;}
        public string CodeLetters {get; set;}
        public string Crncy {get; set;}
    

    Please, read MSDN for more info: Access Modifiers

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

Sidebar

Related Questions

Here is the problem: Remove specified characters from a given string. Input: The string
I wanna get all input from my pages timeline. so I read graph.facebook.com/pageid/feed with
I'm trying to extract all input elements from a form. When I parse the
Is there any way to disable all input fields in an div container with
I want to know if the code below removes all input type='text' values back
I'm trying to get all buffered input from cin . I tried getline ,
I'm trying to get all the input elements from a certain form from jQuery
Should I validate input parameters on all functions I create? Input isn't passed from
I've written some basic code to parse a CSV file and input the data
I am designing a sales invoice form. I am able to pull data from

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.