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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:38:39+00:00 2026-05-23T14:38:39+00:00

From my understanding, ReadAllLines would open a file, and then return all the lines

  • 0

From my understanding, ReadAllLines would open a file, and then return all the lines within that file, and then closes that file/stream. Now I have this piece of code:

try
{
    string[] lines = File.ReadAllLines(path);
}
catch(IOException)
{
    Console.WriteLine("File doesnt exist in : " + path);
}

I did that so that if the file within the path directory doesnt exist, it would throw an error message. My question: is that necessary? Since I dont know how ReadAllLines() was implemented by microsoft, I dont really know if it already had a try catch built-in within the function implementation..

I however, can “guess” that ReadAllLines() would always close the file stream everytime it finishes reading it. that is the reason I did not run the cleanup code that is supposed to be included within the finally{} block.

Can somebody explain/give me confirmation about this? Any help would be appreciated. Let me know if the question is not clear. Thank you.

  • 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-23T14:38:40+00:00Added an answer on May 23, 2026 at 2:38 pm

    I looked at the source in ILSpy and it looks like it does the following:

    [SecuritySafeCritical]
    public static string[] ReadAllLines(string path)
    {
    if (path == null)
    {
        throw new ArgumentNullException("path");
    }
    if (path.Length == 0)
    {
        throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"));
    }
    return File.InternalReadAllLines(path, Encoding.UTF8);
    }
    

    And the method InternalReadAllLines:

    private static string[] InternalReadAllLines(string path, Encoding encoding)
    {
    List<string> list = new List<string>();
    using (StreamReader streamReader = new StreamReader(path, encoding))
    {
        string item;
        while ((item = streamReader.ReadLine()) != null)
        {
            list.Add(item);
        }
    }
    return list.ToArray();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From my understanding of findstr, it looks for text within files. What, then, is
From my understanding, Lua is an embeddable scripting language that can execute methods on
My understanding of Hibernate is that as objects are loaded from the DB they
My understanding is that it's advised testers are separate from developers, i.e you obviously
Are there any understanding / maintainability issues that result from code like inVar1 ==
It is my understanding that although Mercurial has support from branches, the community generally
from my understanding, require pastes code into the calling php file. what if you
From my understanding, os.popen() opens a pipe within Python and initiates a new sub
From my understanding of PHP documentation, setting custom error handler (which cannot catch all
My understanding from reading the specification ( http://www.ietf.org/rfc/rfc2445.txt ) is that the : character

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.