What is the official marketing name for C# 4? - c#

What is the official marketing name for C# 4?
Apress writes "Visual C# 2010 Recipes"
Apress also writes "Pro C# 2010 and the .NET 4 platform"
O'Reilly also writes "Microsoft Visual C# 2010"
Jon Skeet and Scott Hanselman both write C# 4
yet Dino Esposito writes C# 4.0
this MSDN page is entitled Visual C# 2010 Samples, refers to C# 4.0, and people writing in the comments refer to both C# 4 and C# 4.0
If we are going to publish training material about C# 4, what term should we use?

Microsoft Visual C# 2010 is the C# specific part of the integrated development environment Microsoft Visual Studio 2010.
C# 4.0 is the language.
Microsoft .NET Framework 4.0 is the framework.
It is common to shorten 4.0 to 4.
This is a response to Adrian Grigores comment "The .NET version does determine the syntax and semantics of the C# language".
There are (at least) three partially independent version numbers - the .NET Framework version, the Common Language Runtime (CLR) version, and the C# version (see this StackOverflow question for a quite comprehensive list of Framework and CLR versions).
The C# version determines what language features are available. Language features are based on .NET Framework features - the included framework assemblies and CLR version. Finally every .NET Framework versions includes a specific CLR version that basically determines what is valid Common Intermediate Language (CIL) code and how it must be interpreted. Some examples.
C# 3.0 introduces automatic properties. This feature is build into the compiler and does not rely on new functionalities in the .NET Framework assemblies or even the Common Language Runtime (the .NET Framework 3.0 still contains the CLR 2.0). Therefore it is possible to build an application using automatic properties and targeting the .NET Framework 2.0 (maybe even 1.0 and 1.1).
C# 3.0 introduces LINQ. This feature is mainly build into the compiler but partly relies on assemblies new in the .NET Framework 3.0. LINQ to Objects for example relies on the new System.Core.dll containing the Enumerable class. It is however possible to fake this dependencies and therefore use LINQ to Objects with the .NET Framework 2.0.
C# 2.0 introduces generics. This feature relies on extension of the CIL in the CLR 2.0. Therefore it is not possible to use generics with the .NET Framework 1.0 and 1.1.

I'd go with C# 4.0
The first and third book you quoted refers to the visual studio subproduct (Visual C#), That's why they are using 2010 as the "version" number.
So since you you are going to write an article about C#, not Visual Studio, It's either 4 or 4.0. And since '4.0' makes it clearer that you are talking about a version number, C# 4.0 seems like the best choice to me.

The official name of the language is Visual C# <version>
I'll look for a reference .
Edit:
The ECMA-334 standard consistently calls it C#. So that is the name of the language.
Microsoft calls their implementation Visual C#. The other implementations (that I know of) are Mono C# and Rotor C#
And while the IDE is called Visual Studio <versionyear>, I think C# 2010 is a definite misnomer. But that doesn't lower its marketing value.

While the real technical name is C# 4.0 for the latest C# version, 2010 is the IDE's version.
For marketing purposes, 2010 might be used instead of 4.0, because people new to the language might be more tempted to the year number for it indicates that the book is tackling the technology with its recent update.

I'd say the language is C# 4.0, the tool is Visual C# 2010 (like Visual C# 2010 Express).

I would opt for C#4.0.
In the past you had
.NET 1.0 (C# 1.0)
.NET 1.1 (C# 1.0)
.NET 2.0 (C# 2.0)
.NET 3.0 (C# 2.0)
.NET 3.5 (C# 3.0)
and now
.NET 4.0 (C# 4.0)

The language is C# 4.0. The product is Visual C# 2010.
C:\Users\pminaev>csc /?
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
and then opening "%ProgramFiles%\Microsoft Visual Studio 10.0\VC#\Specifications\1033\CSharp Language Specification.doc", on the very first page
C# Language Specification
Version 4.0

IMHO i would call it by it's version.. so C# 4.0. Previous Versions were called by the same like C# 3.0 etc.
regards

Since C# 4.0 came out and currently can only be developed in Visual Studio 2010 (and no other version of VS), people seem to use both terms interchangeably.
Personally, I would rather see C# 4.0, as that is the version of the language, not of the IDE.

Using C# 4.0 may be the official name, but especially if your book is targeted to those 'less in the know', than adding 2010 and whatnot may let people know which version of Visual Studio you are talking about. If it's for professionals, you'll have no problem throwing around C# 4, but for beginners, saying C# 2010 will tell them the IDE they need to use. It's clearer, though not official.

Related

Does C# 8 support the .NET Framework?

In Visual Studio 2019 Advanced Build settings, C# 8 does not appear to be available for a .NET Framework project, only (as in the picture below) for a .NET Core 3.0 project:
Does C# 8 support the .NET Framework?
Yes, C# 8 can be used with the .NET Framework and other targets older than .NET Core 3.0/.NET Standard 2.1 in Visual Studio 2019 (or older versions of Visual Studio if you install a NuGet package).
The only thing required is to set language version to 8.0 in the csproj file. You can also do this in Directory.Build.props to apply it to all projects in your solution. Read below for how to do this in Visual Studio 2019, version 16.3 and newer.
Most - but not all - features are available whichever framework is targeted.
Features that work
The following features are syntax changes only; they work regardless of framework:
Static local functions
Using declarations
Null-coalescing assignment
Readonly members
Disposable ref structs
Positional patterns
Tuple patterns
Switch expressions
Nullable reference types are also supported, but the new nullable attributes required to design the more complex nullable use cases are not. I cover this in more detail further down in the "gory details" section.
Features that can be made to work
These require new types which are not in the .NET Framework. They can only be used in conjunction with "polyfill" NuGet packages or code files:
Asynchronous streams - Microsoft.Bcl.AsyncInterfaces
Indices and ranges
Default interface members - do not, cannot, and never will work
Default interface members won't compile under .NET Framework and will never work because they require runtime changes in the CLR. The .NET CLR is now frozen as .NET Core is now the way forward.
For more information on what does and doesn't work, and on possible polyfills, see Stuart Lang's article, C# 8.0 and .NET Standard 2.0 - Doing Unsupported Things.
Code
The following C# project targetting .NET Framework 4.8 and using C# 8 nullable reference types compiles in Visual Studio 16.2.0. I created it by choosing the .NET Standard Class Library template and then editing it to target .NET Framework instead:
.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net48</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
.cs:
namespace ClassLibrary1
{
public class Class1
{
public string? NullableString { get; set; }
}
}
I then tried a .NET Framework 4.5.2 WinForms project, using a legacy .csproj format, and added the same nullable reference type property. I changed the language type in the Visual Studio Advanced Build settings dialog (disabled in 16.3) to latest and saved the project. Of course as this point it doesn't build. I opened the project file in a text editor and changed latest to preview in the build configuration PropertyGroup:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<LangVersion>preview</LangVersion>
I then enabled support for nullable reference types by adding <Nullable>enable</Nullable> to the main PropertyGroup:
<PropertyGroup>
<Nullable>enable</Nullable>
I reloaded the project, and it builds.
Visual Studio 2019
There has been a major change in the RTM version of Visual Studio 2019 version 16.3, the launch version for C# 8.0: the language selection dropdown has been disabled:
Microsoft's rationale for this is:
Moving forward, ... each version of each framework will have a single
supported and default version, and we won't support arbitrary
versions. To reflect this change in support, this commit permanently
disables the language version combo box and adds a link to a document
explaining the change.
The document which opens is C# language versioning. This lists C# 8.0 as the default language for .NET Core 3.x ONLY. It also confirms that each version of each framework will, going forward, have a single supported and default version and that the framework-agnosticism of the language can no longer be relied on.
The language version can still be forced to 8 for .NET Framework projects by editing the .csproj file.
The gory details
When this answer was first written, C# 8 was in preview and a lot of detective work was involved. I leave that information here for posterity. Feel free to skip it if you don't need to know all the gory details.
The C# language has historically been mostly framework neutral - i.e. able to compile older versions of the Framework - although some features have required new types or CLR support.
Most C# enthusiasts will have read the blog entry Building C# 8.0 by Mads Torgersen, which explains that certain features of C# 8 have platform dependencies:
Async streams, indexers and ranges all rely on new framework types
that will be part of .NET Standard 2.1... .NET Core 3.0 as well as
Xamarin, Unity and Mono will all implement .NET Standard 2.1, but .NET
Framework 4.8 will not. This means that the types required to use
these features won’t be available on .NET Framework 4.8.
This looks a bit like Value Tuples which were introduced in C# 7. That feature required new types - the ValueTuple structures - which were not available in NET Framework versions below 4.7 or .NET Standard older than 2.0. However, C# 7 could still be used in older versions of .NET, either without value tuples or with them by installing the System.ValueTuple Nuget package. Visual Studio understood this, and all was fine with the world.
However, Mads also wrote:
For this reason, using C# 8.0 is only supported on platforms that implement .NET Standard 2.1.
...which if true would have ruled out using C# 8 with any version of the .NET Framework, and indeed even in .NET Standard 2.0 libraries which only recently we were encouraged to use as a baseline target for library code. You wouldn't even be able to use it with .NET Core versions older than 3.0 as they too only support .NET Standard 2.0.
The investigation was on! -
Jon Skeet has an alpha version of Noda-Time using C# 8 ready to go which targets .NET Standard 2.0 only. He is clearly expecting C# 8/.NET Standard 2.0 to support all frameworks in the .NET family. (See also Jon's blog post "First steps with nullable reference types").
Microsoft employees have been discussing the Visual Studio UI for C# 8 nullable reference types on GitHub, and it is stated that they intend to support the legacy csproj (pre-.NET Core SDK format csproj). This is a very strong indication that C# 8 will be usable with the .NET Framework. [I suspect they will backtrack on this now that the Visual Studio 2019 language version dropdown has been disabled and .NET has been tied to C# 7.3]
Shortly after the famous blog post, a GitHub thread discussed cross-platform support. An important point which emerged was that .NET Standard 2.1 will include a marker that denotes that default implementations of interfaces is supported - the feature requires a CLR change that will never be available to the .NET Framework. Here's the important bit, from Immo Landwerth, Program Manager on the .NET team at Microsoft:
Compilers (such as C#) are expected to use the presence of this field to decide whether or not to allow default interface implementations. If the field is present, the runtime is expected to be able to load & execute the resulting code.
This all pointed to "C# 8.0 is only supported on platforms that implement .NET Standard 2.1" being an oversimplification, and that C# 8 will support the .NET Framework but, as there is so much uncertainty, I asked on GitHub and HaloFour answered:
IIRC, the only feature that definitely won't appear on .NET Framework is DIM (default interface methods) as that requires runtime changes. The other features are driven by the shape of classes that might never be added to the .NET Framework but can be polyfilled through your own code or NuGet (ranges, indexes, async iterators, async disposal).
Victor Derks commented that "The new nullable attributes required to design the more complex nullable use cases are only available in System.Runtime.dll that ships with .NET Core 3.0 and .NET Standard 2.1... [and] incompatible with .NET Framework 4.8"
However, Immo Landwerth commented that "The vast majority of our APIs didn't need any custom attributes as the types are either fully generic or not-null" under the article Try out Nullable Reference Types
Ben Hall raised the issue Availability of nullable attributes outside of Core 3.0 on GitHub, with the following comments from Microsoft employees being of note:
C# 8 will be fully supported on .net core 3.0 and .net standard 2.1 only.
If you manually edit the project file to use C# 8 with .net core 2.1,
you are in unsupported territory. Some C# 8 features will happen to
work well, some C# 8 features will work not too well (e.g. poor
performance), some C# 8 features will work with extra hacks, and some
C# 8 features will not work at all. Very complex to explain. We do not
actively block it so the expert users who can navigate through it can
do so. I would not recommend this unsupported mix&match to be used
broadly.
(Jan Kotas)
People like you who are willing understand -- and work around them --
are free to use C# 8. The point is, not all language features will work
on down-level targets.
(Immo Landwerth)
Caveat emptor
The C# 8/.NET Framework combination is not officially supported by Microsoft. It is, they say, for experts only.
According to this blog entry the language is indeed tied to the framework:
This means that the types required to use these features won’t be available on .NET Framework 4.8. Likewise, default interface member implementations rely on new runtime enhancements, and we will not make those in the .NET Runtime 4.8 either.
For this reason, using C# 8.0 is only supported on platforms that implement .NET Standard 2.1. The need to keep the runtime stable has prevented us from implementing new language features in it for more than a decade. With the side-by-side and open-source nature of the modern runtimes, we feel that we can responsibly evolve them again, and do language design with that in mind. Scott explained in his Update on .NET Core 3.0 and .NET Framework 4.8 that .NET Framework is going to see less innovation in the future, instead focusing on stability and reliability. Given that, we think it is better for it to miss out on some language features than for nobody to get them.

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?
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 async-await 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.
you can use features of lastest visual studio editions (2013, 2015), but the code must be according to 2.0 specifications to allow a .NET 2.0 compilation (older versions)
Yes, C# and .Net versions are dependent. According to my understanding C# is a programming language which works using .Net Technology.
Learning C# means learning the basic syntax, which is almost the same in all .Net versions. So for learn c#, it doesn't matter which .Net version you must target. Different .Net versions adds up certain new features or functionality. Any way its better to understand latest .Net version which will help you in projects.
You can use C# features from earlier versions with later versions of .Net, for example, you can use any C# 2.0 feature with .Net 3.5, this does not work the other way arround, so you cannot use .Net 3.5 features with the c# 2.0 compiler.
For more details see: https://msdn.microsoft.com/en-us/library/ff602939(v=vs.110).aspx
C# 6.0 is available in .NET 5.0.
It depends on the CLR. C# 4, 4.5 and 4.5.1 are using the CLR Version 4.
Yes C# is dependent on .net versions. The dependence between the both is on features and technologies provided. Refer following link:
https://msdn.microsoft.com/en-us/library/bb822049%28v=vs.110%29.aspx

How does C# version, VS version, and .NET framework version, etc fit together?

I am quite confused by how all the parts to the MS stack fit together. How does the C# version, Visual Studio version, .NET framework version, and ASP.NET version (is this the same as the .net version?) fit together for a given project?
For example, if I use Visual Studio 2010 for a project that targets .NET framework 2, how do I know which C# or ASP.NET features I can use?
The C# version controls which language feature you can use; it is independent of everything else. (since it's only the compiler)
You can use (most) newer language features even when targeting older frameworks.
However, some of these features (eg, dynamic or NoPIA) depend on features in a specific .Net Framework version.
The .Net Framework version controls which parts of .Net you can use; some .Net features (eg, LINQ or the TPL) were introduced in newer versions (3.5 and 4.0, respectively)
To make things more complicated, ASP.Net invokes the C# compiler at runtime to compile ASPX or Razor views (and standalone files in Web Site projects), so you can't use newer language features than your framework version in such scenarios.
The C# version is the version of the compiler invoked to compile source code, the VS version is the version of the visual studio IDE, which may support multiple framework versions. The version of the framework affects the version of the .NET BCL (base class libraries) that are available.
Thus, if you target the 2.0 Framework, as in your example, you can only use BCL libraries available in the 2.0 framework. Thus, you cannot use System.Linq.
However, since VS2010 uses the C# 4 compiler, you can use C# 4 compiler features , such as default parameters, and still target an older framework.
Thus, this will compile and run under the 2.0 Framework when built from VS2010 because the C# 4 compiler handles default parameters at compile-time:
class Program
{
public static void HelloWorld(string x = "Hi")
{
Console.WriteLine(x);
}
static void Main(string[] args)
{
HelloWorld();
HelloWorld("Buyah");
}
}
Check out the table in the Wikipedia entry for C#, which gives you a good overview of different versions of C# language (and compiler), and the version of .NET and Visual Studio they depend on.
Remember that Visual Studio is usually backwards compatible, so you can write C# 2.0 code against the .NET Framework 2.0 even in Visual Studio 2010.
The Visual Studio version controls which C# / .NET versions you can use; you can't write C# using .NET 4.0 features in Visual Studio 2005, as the IDE was released prior to the C# version. However you can go backwards, i.e. target .NET 2.0 from VS 2010.
The versions of C# with respect to framework versions and IDEs are as follows, starting with .NET / C# 2.0 and VS 2005:
VS 2005 | .NET 2.0 and prior | C# 2.0 and prior
VS 2008 | .NET 3.5 and prior | C# 3.0 and prior
VS 2010 | .NET 4.0 and prior | C# 4.0 and prior
VS 11 (beta) | .NET 4.5 and prior | C# 5.0 and prior
Visual Studio is the IDE. It supports a number of versions of .Net, depending on which version of VS you have. VS2010 supports as far back as .Net 2 and as high as .Net 4 (not counting current betas)
.Net has its own version based on the features of the library
Independently from each other and .Net, C# and VB have their own version numbers. VB took over from classic VB and at last I checked was on 11. C# is close in line with the .Net number. These change when the language itself gets new features that are independent of the libarary.
ASP.Net has its own version as well, again, based on different features.
They are all interrelated but not dependent on one another. Generally, they all go up a version when .net does, but occasionally they'll release new features to ASP.Net before updating the language or framework.
A table will suit better here, but here is my answer:
Language: C# 1, .NET Frameworks 1.0, 1.1, VS 2003
Language: C# 2, .NET Frameworks 2.0, VS 2005 (main feature added:
generics)
Language: C# 3, .NET Framework 3.0, 3.5 (actually they are based on
version 2.0), VS 2008 (main features added: LINQ (language), WCF, WPF,
WF (technologies)
Language: C# 4, .NET Framework 4.0, VS 2010 (main feature added: the
dynamic type)
By the way: VS 2008, 2010 can target .NET Frameworks beginning from version 2.0

Current position of Java Language Conversion Assistant and J#

A recent answer to a question on converting Java to C# suggested I should use Java Language Conversion Assistant and pointed to:
http://msdn.microsoft.com/en-us/library/7tatw8a2%28VS.80%29.aspx
I cannot find JLCA on my Visual Studio (9.0.30729.1) and on looking at Wikipedia (http://en.wikipedia.org/wiki/J_Sharp) I find:
Retirement of the J# language and Java
Language Conversion Assistant from
future versions of Visual Studio,
since the existing J# feature set
largely meets customer needs and usage
of J# is declining. The last version
shipping with Visual Studio 2005 will
be supported until 2015 as per the
product life-cycle strategy.
I'd be grateful for an overview of whether I can use and should be using either J# or JLCA and if so how to install and use them.
Something that might help - there is an open source project IKVM.Net that can recompile your java bytecode into .net byte code. Afterwards, you could use Reflector to decompile the generated .net assembly into C# for additional modifications. IKVM comes with a fully converted java class library as .net assembly, which you can continue using from that code, while slowly moving to the core .net libraries.
From this and other answers it seems that J# should be deprecated.

Can I write the code based on .NET Framework 4.0 without vs 2010?

I downloaded and installed the .net framework 4.0, but I didn't install VS 2010, because VS 2010 require the high-performance computer hardware. I have no but I expect to taste the C# 4.0 feature.
you need the .net 4.0 compiler, which at the moment is only available with vs2010.
This thread might answer your question
Where I can download compiler for C# 4.0 without Visual Studio 2010?
The .NET framework client profile includes the compiler (csc.exe). For example, on my machine, it's at:
c:\Windows\Microsoft.NET\Framework64\v4.0.20506\csc.exe
The 32-bit version is at:
c:\Windows\Microsoft.NET\Framework\v4.0.20506\csc.exe
If you're familiar with the command-line compiler syntax, most applications can be written just using it, notepad and referencing the appropriate assemblies. It won't be a terribly pleasant experience though.

Categories

Resources