Callum Holden
Callum Holden

Reputation: 177

leading '.' or '! ' can only appear inside a 'with' statement

I am trying to find some code which will only read in lines from a text file which have data (so non blank lines).

I came across this method:

fileData = File.ReadAllLines("textFile.txt").Where(i >= !String.IsNullOrEmpty(i))

However, I am getting the error as posted in the title and cannot seem to find much online as to what the error means and how to solve it.

If anyone can help me understand what this is that would be great.

Many thanks!

Upvotes: 3

Views: 2263

Answers (1)

Matt Wilko
Matt Wilko

Reputation: 27322

The code you posted is a mixture of C# and VB.

As the question is tagged VB.NET and the title of the question refers to With Statements, I assume that is language you are trying to get a solution in.

The Actual VB.NET you are looking for is as follows:

fileData = File.ReadAllLines("textFile.txt").Where(Function(i) Not String.IsNullOrEmpty(i))

! in C# is equivalent to Not in VB

i => in C# is equivalent to Sub(i) or Function(i)

but note that pasting => into Visual Studio converts it to >= automatically (when coding in VB)

Upvotes: 8

Related Questions