-4

This is my method. This "sr.ReadToEnd" gives an error. "Argument 1: Cannot covert from group method to bool". It suggest that "ReadToEnd" tchange to "ReadToEndAsync". But it also gives me the same error. I am novel to C#. SO I want to know,

What is group method?

Why this gives me that error?

What is the difference between "ReadToEnd" and "ReadToEndAsync"

<pre>
 private static void TestExceptionHandling()
    {
        StreamReader sr = null;
        try
        {
            sr = File.OpenText(@"E:\4th(Final) Year\LastSemester\SM\Alternatives1_2.docx");
            Console.WriteLine(sr.ReadToEnd);
        }
        catch (FileNotFoundException FNF)
        {
            Console.WriteLine(FNF.Message);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
TKrish
  • 49
  • 1
  • 8
  • 5
    `sr.ReadToEnd()` – Pikoh Apr 11 '17 at 15:37
  • 1
    .docx is a binary file. You're not going to be able to read the contents of it this way. You need a library that understands the format. – mason Apr 11 '17 at 15:38
  • But I tried after using .txt. But it doesn't work. – TKrish Apr 11 '17 at 15:41
  • A text file will work, but a .docx file won't. That's like saying "my car's engine won't start, so I poured Coca Cola into the gas tank and it still didn't work." Of course it won't work, it's the wrong thing to use. – mason Apr 11 '17 at 15:43

2 Answers2

1

You need to actually call the ReadToEnd method and write its return value. Try replacing

Console.WriteLine(sr.ReadToEnd);

with

Console.WriteLine(sr.ReadToEnd());
Connell.O'Donnell
  • 3,603
  • 11
  • 27
  • 61
1

Both sr.ReadToEnd() and sr.ReadToEndAsync() are methods and you are using them as properties/variables that's why you are getting the error.

Coming to difference between them ReadToEnd is synchronous method runs on main thread and ReadToAsync is asynchronous runs on separate thread

Krishna
  • 1,945
  • 1
  • 13
  • 24