2

I wanted to try the "new" async/await (yeah, I'm late to the party) so I fired up LINQPad 4.5.1 which is currently the latest non-beta. After switching to "C# Program" and input the following code, sans comment;

// "Invalid token 'void' in class, struct, or interface member declaration"
// - But compiles with `async` removed
async void foo () {
}

void Main()
{
    foo();
}

But it .. "doesn't work" as indicated.

This error seems to indicate that LINQPad is using C#4 and not C#5 although the website does say "LINQPad supports everything in C# 5.0 and Framework 4.x" and others don't seem to have this problem.

What causes this error, and how can it be resolved?

Community
  • 1
  • 1
user2864740
  • 60,010
  • 15
  • 145
  • 220

2 Answers2

3

Even if this is not the solution for this particular issue, it may come handy for people like me that arrived to this question looking a fix for a compile error with the Task<T> return type because I was missing a using. The way to add it on LinqPad is pressing F4 > Namespace Imports tabs and adding at the bottom of the list System.Threading.Tasks then press Ok.

You can also set this new list as the default for the new queries pressing Set as default for new queries

Go by shortcut

Other way to access this tab is by the top menu Query > Namespace Imports

Go by the query menu

Luxant
  • 141
  • 1
  • 7
1

Well, that was .. silly of me. The current machine had .NET 4 - not 4.5 - installed.

After installing .NET 4.5 "it works".

user2864740
  • 60,010
  • 15
  • 145
  • 220