Hind Forsum
Hind Forsum

Reputation: 10527

Does C# 6.0 support .NET Core, or does .NET Core respond to higher version of C#?

I've just installed .NET Core 1.0 and run the sample hello world.

  1. Is there any relationship with .NET Core 1.0 and its default C# version?
  2. How can I know the C# version of this .NET Core installation via a command line utility?

Upvotes: 4

Views: 2396

Answers (3)

Itay Podhajcer
Itay Podhajcer

Reputation: 2664

The difference is more between .Net Core and the full .Net Framework, Meaning, you'll be able to use the same syntax, but you'll find differences in the classes you can/can't use and sometimes, in the way you use them.

Upvotes: 1

Eli Arbel
Eli Arbel

Reputation: 22747

.NET Core 1.0 ships with C# 6. You can see that in the references:

enter image description here

Microsoft.CodeAnalysis* are the NuGet packages for the C# compiler. Versions 1.x correspond to C# 6, and 2.x (currently in beta) are C# 7.

You can also see this dependency on NuGet: Microsoft.NETCore.App.

When C# 7 comes out, it would probably be possible to use the new compiler by adding its package to a .NET Core project.

Upvotes: 5

Jon Skeet
Jon Skeet

Reputation: 1503599

The language itself isn't generally tied to a specific runtime/framework, although some language features do require framework features. (For example, interpolated strings are a bit more flexible on .NET 4.6 than on .NET 2.0 due to the presence of FormattableString.) However, there are two things to consider:

  • The version of the C# compiler supported by the SDK you've installed (dotnet cli)
  • The version of the C# compiler packages that is supported by a particular framework version

The SDK supports C# 6 out of the box. I would personally expect the C# 7 version of the Roslyn packages to support .NET Core as well (e.g. targeting netstandard1.5), so code that compiles more code at execution time should be fine on that front. I don't know what the plan is in terms of tying compiler versions to SDK versions - I suspect that will become clearer when the project.json to msbuild transition is complete.

I don't know of any way of determining what language version a particular SDK supports out of the box - it would be reasonably easy to come up with a sequence of small classes which exercise particular language features and see if they compile, of course. Trickier would be to come up with code that builds with multiple versions but gives different results; there are ways of doing that between consecutive language versions (at least 2-3, 3-4, 4-5... not sure about 5-6) but they're slightly more convoluted.

Upvotes: 4

Related Questions