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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:25:22+00:00 2026-05-23T18:25:22+00:00

Consider this while loop that keeps nulling my values once it has finished. The

  • 0

Consider this while loop that keeps nulling my values once it has finished.

The counterm string is now null at the end of the program. How can we carry the value from the while loop?

void somefunction() {   
    try {                  
      using (StreamReader sr = new StreamReader("Counter.txt"))
      {
        String line;
        while ((line = sr.ReadLine()) != null)
        {
            Console.WriteLine(line);
            string countern = line + "_1";
            string counterm = line + "_2";
            int counter = Convert.ToInt32(line);
            sr.test(counterm);
        }
      }
    }
    catch (Exception e)
    {
        // Let the user know what went wrong.
    Console.WriteLine("The file could not be read:");
    Console.WriteLine(e.Message);
    Thread.Sleep(60000);            
    }
}
public static void test(counterm)
{
        Console.WriteLine(counterm);
        Console.ReadLine();
}
  • 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-23T18:25:22+00:00Added an answer on May 23, 2026 at 6:25 pm

    counterm is a variable local to your loop. Also your code does not compile because it’s incomplete but my suggestion would be something like this:

    string ParseCounters()
    {
        string counterm = "";
    
        ...
        String line;
        while ((line = sr.ReadLine()) != null)
        {
            ...
            counterm = line + "_2"
        }
        ...
    
        return counterm;
    
    }
    
    public static void test()
    {
        Console.WriteLine(ParseCounter());
        Console.ReadLine();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this code: import socket store = [] scount = 0 while True: scount+=1
Consider this: public class TestClass { private String a; private String b; public TestClass()
get current array position pointer while doing foreach $object->result_array() Hi, consider this, a case.
I encountered this problem while solving a practice test Consider this C code to
Consider this condition that exists in a template that is called recursively: <xsl:if test=$i
I frequently have code that looks something like this: if (itm != null) {
consider this simple code: $q=mysql_query('SELECT [...]'); while($row=mysql_fetch_assoc($q)){ //Do something with data //And write how
While using some regex in C#, I'm facing the following problem : Consider this
take this simple loop while(1) { $data = file_get_contents('randomfiles.img'); $resource = imagecreatefromstring($data); //> do
Consider this JavaScript Code: <script type=text/javascript> function loop(Message){ document.getElementById('output').innerHTML = document.getElementById('output').innerHTML + Message +

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.