0

Upon running this code:

foreach (string drive in Environment.GetLogicalDrives())    
    Console.WriteLine("Drive: {0}", drive);

    Console.WriteLine("OS: {0}", Environment.OSVersion);
    Console.WriteLine("Processor count: {0}", Environment.ProcessorCount);
    Console.WriteLine(".NET version: {0}", Environment.Version);

I get

enter image description here

When I downloaded and started the .NET installer, I was told that the 4.5 version was already installed. Is there a difference between the version name, and the actual version number?

programstinator
  • 1,354
  • 3
  • 12
  • 31

3 Answers3

4

Yes - basically .NET 4.5 is an in-place replacement for .NET 4.0, so Environment.Version will return the same version number for the first 3 parts. The build part of the version number (18010 in your case) is different between .NET 4.0 and .NET 4.5 (and potentially updates to each) but the major/minor/patch level is 4.0.30319 in both cases.

It's confusing as heck, but that's the situation, I'm afraid.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
2

.NET 4.5 is a drop-in replacement for 4.0 - the version number is indeed what you see.

Check the versions of the assemblies in the reference assemblies directory.

Community
  • 1
  • 1
Oded
  • 489,969
  • 99
  • 883
  • 1,009
0

Starting with .NET Core 3.0 (and .NET Standard 2.1) situation is changed and now Environment.Version working properly.

System.Console.WriteLine($"Environment.Version: {System.Environment.Version}");

// Old result
//   Environment.Version: 4.0.30319.42000
//
// New result
//   Environment.Version: 3.0.0

See documentation for further information.

picolino
  • 4,856
  • 1
  • 18
  • 31