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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:13:28+00:00 2026-05-18T03:13:28+00:00

The question that I have is regarding converting the process of reading lines from

  • 0

The question that I have is regarding converting the process of reading lines from a text file into an array instead of just reading it.

The error in my codes appear at string[] lines = File.ReadLines("c:\\file.txt"); with cannot implicitly convert….

Can someone please advise on the codes to save the results in an array format? I’ve placed the ReadAllLines code which is able to save the results in an array too. Thanks!

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

namespace Testing
{
class Analysis
{
    static void Main()
    {
        string[] lines = File.ReadLines("c:\\file.txt");

        foreach (string r in lines)
        {
            Console.WriteLine("-- {0}", r);
        }

        // Keep the console window open in debug mode.
        Console.WriteLine("Press any key to exit.");
        System.Console.ReadKey();
    }
}
}

ReadAllLines Codes:

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

namespace Testing
{
class ReadFromFile
{
    static void Main()
    {
        string[] lines = System.IO.File.ReadAllLines
        (@"C:\Users\Public\TestFolder\WriteLines2.txt");

        System.Console.WriteLine("Contents of writeLines2.txt =:");
        foreach (string line in lines)
        {
            Console.WriteLine("\t" + line);
        }

        // Keep the console window open in debug mode.
        Console.WriteLine("Press any key to exit.");
        System.Console.ReadKey();
    }
}
}
  • 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-18T03:13:29+00:00Added an answer on May 18, 2026 at 3:13 am

    File.ReadLines() returns an object of type System.Collections.Generic.IEnumerable<String>

    File.ReadAllLines() returns an array of strings.

    If you want to use an array of strings you need to call the correct function.

    You could use Jim solution, just use ReadAllLines() or you could change your return type.

    This would also work:

    System.Collections.Generic.IEnumerable<String> lines = File.ReadLines("c:\\file.txt");
    

    You can use any generic collection which implements IEnumerable, such as IList<String>.

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

Sidebar

Related Questions

From a previous question I have seen that the CLR has workstation and server
Following on from this question I now have code that can attach to a
I'm an actionscript developer getting into jquery/javascript development. I have a question regarding event
Question: I have a question that is apparently not answered by this already-asked Bash
I am learning LINQ and have a very simple question that I think will
Question So I've recently came up with some new possible projects that would have
My question is the following. I have xml that is versioned by a namespace.
Question We have a large number of xml configuration files that we want merged
Question Is there a way to have a method that will always run anytime
I have a two part question Best-Practice I have an algorithm that performs some

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.