Search code examples
c#.netframeworks

Are C# and .NET versions dependent on each other?


I'm just starting to learn C# and its relationship to .NET. If say I wanted to take advantage of the latest C# language conventions, but wanted to target, say a .NET 2.0 framework, could I do that? Or does using the latest C# mean I have to use the latest .NET?


Solution

  • C# as a language is not dependent on .net framework.

    For example: Extension methods is a feature released with C# 3.0 which came along with .Net 2.0. Extension methods depends on ExtensionAttribute which lives in "mscorlib.dll" which was added in .Net 3.5. But you can use Extension methods in .Net 2.0 given that you provide your own ExtensionAttribute in your library itself. It doesn't needs to be in mscorlib. Refer this question for more info.

    As we know is new in C# 5.0 which was released with .Net 4.5, but we can use async-await in .Net 4.0 itself.

    Sameway, most of the dependencies of language features can be defined in your own assembly to make it work. So it doesn't need the particular .Net framework version.