Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

asp.net

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?

like image 461
Oxed Frederik Avatar asked May 17 '12 13:05

Oxed Frederik


People also ask

How does C operate?

c is called the source file which keeps the code of the program. Now, when we compile the file, the C compiler looks for errors. If the C compiler reports no error, then it stores the file as a . obj file of the same name, called the object file.

What does %c mean in C?

%d is used to print decimal(integer) number ,while %c is used to print character . If you try to print a character with %d format the computer will print the ASCII code of the character.

How do you explain C?

C is a structured, procedural programming language that has been widely used both for operating systems and applications and that has had a wide following in the academic community. Many versions of UNIX-based operating systems are written in C.

Is C hard to write?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.


3 Answers

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.

like image 58
SLaks Avatar answered Oct 12 '22 22:10

SLaks


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");
    }
}
like image 42
James Michael Hare Avatar answered Oct 12 '22 22:10

James Michael Hare


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.

like image 40
Avner Shahar-Kashtan Avatar answered Oct 12 '22 22:10

Avner Shahar-Kashtan