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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:55:22+00:00 2026-05-18T08:55:22+00:00

I wrote a simple program, here’s what it looks like, some details hidden: using

  • 0

I wrote a simple program, here’s what it looks like, some details hidden:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace routeaccounts
{
    class Program
    {
        static void Main(string[] args)
        {
            //Draw lines from source file
            var lines = File.ReadAllLines("accounts.txt").Select(p => p.Split('\t'));
            //Convert lines into accounts
            var accounts = lines.Select(p => new Account(p[0], p[1], p[2], p[3]));
            //Submit accounts to router
            var results = accounts.Select(p => RouteAccount(p));
            //Write results list to target file
            WriteResults("results.txt", results);
        }

        private static void WriteResults(string filename, IEnumerable<Result> results)
        {
            ... disk write call ...
        }

        private static Result RouteAccount(Account account)
        {
            ... service call ...
        }
    }
}

My question is this – obviously, when selecting from a data context, execution is deferred. If you notice, in the first statement of the ‘Main’ function, I’m querying from File.ReadAllLines(“accounts.txt”). Is this a bad choice? If I enumerate the final result, will this statement be repeatedly?

I can simply .ToArray() or grab the results ahead of time, if I know it’s a problem, but I’m interested to know what’s going on behind the scenes.

  • 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-18T08:55:22+00:00Added an answer on May 18, 2026 at 8:55 am

    It’s not going to read the file repeatedly, no – because that part of execution isn’t deferred. It will return an array, and then the call to Select will return you a sequence… the projection will be deferred, but the reading of the file won’t. That array will stay in memory until everything referring to it (directly or indirectly) is eligible for garbage collection… it won’t need to reread the file.

    On the other hand, you may want to read the results using ToList() or something similar anyway – because that way, you get to find out any errors before you start to write the results. It’s quite often a good idea to make sure you’ve got all the data you need before you start executing code with side effects (which I imagine WriteResults does). Obviously it’s less efficient in terms of the amount of data needed in memory at a time though… it’s a balance you’ll have to weigh up yourself.

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

Sidebar

Related Questions

I'm working on learning python, here is a simple program, I wrote: def guesser(var,
Here's a simple program I wrote to find all the non-decreasing-digit numbers of length
I wrote a simple c++ program that prints Hello World! #include <iostream> using namespace
I wrote a c++ program using boost library in Xcode. Here is my code.
I wrote a simple program to solve the math problem: A^2+B^2 = 12 A*B
I wrote a simple program to test a theory that finally block will always
I wrote a simple program in java web forms but i am receiving the
I wrote a simple test program for opencv to see if it's working after
I wrote a simple C program: #include <unistd.h> #include <stdio.h> int main( int argc,
A while back I wrote a simple python program to brute-force the single solution

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.