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, the soft keyboard is actually a dialog window that underlies all
From what little understanding of Cassandra I have, it seems that data locality is
My understanding is that it's advised testers are separate from developers, i.e you obviously
From my understanding $_COOKIE gives me all the cookies in a user's browser. But
from my understanding, require pastes code into the calling php file. what if you
From my understanding, Lua is an embeddable scripting language that can execute methods on
From my understanding, if Hardware supports Cache coherence on a multi-processor system, then writes
From my understanding, this code: Microsoft.VisualBasic.StrDup(3, 123) should return 123123123 . Instead it returns
I have read from multiple sources and from my understanding of the algorithm that
From my understanding, const modifiers should be read from right to left. From that,

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.