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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:52:52+00:00 2026-05-12T13:52:52+00:00

In my C# app I’m trying to feed into ReadLine() a simple text document

  • 0

In my C# app I’m trying to feed into ReadLine() a simple text document with 7 digit strings separated line by line. What I’m attempting to do is grab the next 7 digit string each time the function is called. Here’s what I have so far:

string invoiceNumberFunc()
    {
        string path = @"C:\Users\sam\Documents\GCProg\testReadFile.txt";
        try
        {
            using (StreamReader sr = new StreamReader(path))
            {
                invoiceNumber = sr.ReadLine();

            }

        }
        catch (Exception exp)
        {
            Console.WriteLine("The process failed: {0}", exp.ToString());
        }
       return invoiceNumber;
    }

How do I advance to the next line each time the invoiceNumberFunc() is called?

Thanks in advance.

  • 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-12T13:52:52+00:00Added an answer on May 12, 2026 at 1:52 pm

    You’d need to keep hold of the StreamReader between calls, either passing it into the method as a new parameter or making it a member variable of the class.

    Personally I prefer the idea of it becoming a parameter, so that it never ends up as a member variable – that makes the life-time easier to manage:

    void DoStuff()
    {
        string path = @"C:\Users\sam\Documents\GCProg\testReadFile.txt";
        using (StreamReader sr = new StreamReader(path))
        {
            while (keepGoing) // Whatever logic you have
            {
                string invoice = InvoiceNumberFunc(sr);
                // Use invoice
            }
        }
    }
    
    string InvoiceNumberFunc(TextReader reader)
    {
        string invoiceNumber;
        try
        {
            invoiceNumber = reader.ReadLine();
        }
        catch (Exception exp)
        {
            Console.WriteLine("The process failed: {0}", exp.ToString());
        }
        return invoiceNumber;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 274k
  • Answers 274k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Since you have a link in there, why not use… May 13, 2026 at 2:16 pm
  • Editorial Team
    Editorial Team added an answer If you do not care a minor performance loss, use… May 13, 2026 at 2:16 pm
  • Editorial Team
    Editorial Team added an answer You want to use if ( $('#fNuttig').is(':checked') ) instead of… May 13, 2026 at 2:16 pm

Related Questions

In my C# app I'm trying to feed into ReadLine() a simple text document
I need to pass a Scripting.Dictionary between my C# app and another app. I
In my C# winforms app, I have a datagrid. When the datagrid reloads, I
In my c# app, I've got a list that I navigate with an Enumerator.
In my C# code-behind for an ASP.Net app, I have a variable being set

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.