C# and .NET relation - c#

I know its extensive topic but I have failed to find some basic overview. I would like to know what is exactly the relation between these two. I know I need .NET SP2 to work with VS 2010, so client PC will need to have the same version of .NET I guess.
I would be very grateful if someone could tell me in a few sentences what is .NET and how it relates ti C#

.NET is a framework. What that means is that the .NET platform contains libraries of existing code and architecture from which all applications utilizing it build from. So rather than pouring a new foundation for every house, you already start off with a solid one that has been perfected and improved upon over time. In addition to a starting foundation, the framework serves as a sort of toolbox of existing code that saves you from reinventing the wheel every time you need certain things.
For instance, winforms is an established foundation from which to build windows applications with a rudimentary user interface simply by going to file > new project. You would have to interface with GDI yourself to generate windows forms and user interface if this library of existing code was not there to support you.
C# is simply a programming language. One specifically written with .NET in mind. In fact, most of the .NET framework is written in C# (if not all of it). It's syntax is simply the next progression of the C language, thus transitioning from C++ to C# shouldn't be too difficult. It's a paradigm shift with a lot of things, but at least the syntax is often familiar. Any .NET language is usually compatible with other .NET languages. For instance, I could write a class library in Visual Basic, and you could use that compiled library in your C# program.
Because .NET is a framework, the code you reference in it does not get compiled into your program, rather a reference to code in the framework is all that gets compiled. This means that clients running your program must also have the .NET framework, albeit a stripped down version. They don't need all the development tools that you need so their .NET framework download is a little smaller. Clients running Windows Vista/7 don't need to worry about anything; it's included with their OS. Only certain users running XP would even have to worry about downloading the framework, and most programs accurately detect the requirement and inform the end user to go download it.
All versions of Visual Studio are simply tools to help you build applications and better utilize the .NET framework. I would never recommend coding in any .NET language without at least the express (free) edition of visual studio. Intellisense alone is worth it. That said, it is definitely possible to code something in .NET without the Visual Studio IDE. You could open up notepad right now and write a C# program, compile it with the free compiler, and run it. While Visual Studio 2010 is pretty amazing, and uses the new WPF platform to run, 2008 will serve you just as well. 2010 is optimized for .NET 4 but works just fine when targeting previous versions of .NET as well.
Bottom line:
.NET is a coding framework.
C# is a language built to take advantage of .NET. NOTE: Visual Basic is also a .NET language and choosing between C# and VB is simply a matter of preference.
Visual Studio is a tool to help you in coding for .NET.
That is how they are all related.

(This is probably a duplicate, but the best answer is off-site)
Quoting from Jon Skeet:
Untangling the Versions
There are lots of different versions of different elements of development. You need to distinguish between the versions of Visual Studio (the IDE), C# (the language) and .NET (the framework). It's quite hard to talk about each of these individually without bringing in other pieces, but I'll see what I can do... Note that I'll avoid introducing the CLR versions as well, as most developers don't really need to know about that.
.NET Framework versions
There have been five significant releases of the .NET Framework, excluding service packs. The framework includes the compilers, runtime, and libraries.
1.0 - released in 2002
1.1 - released in 2003
2.0 - released in 2005, with a new CLR (to handle generics and nullable types) and compilers for C# 2 and VB 8.
3.0 - released in 2006, this is just 2.0 plus new libraries: Windows Presentation Foundation, Windows Communication Foundation, Workflow Foundation, and Cardspace
3.5 - released in 2007, this is 3.0 plus new libraries (primarily LINQ and some extra "base" libraries such as TimeZoneInfo) and new compilers (for C# 3 and VB 9)
C# language versions
There are three significant language versions:
C# 1
C# 2, introducing generics, nullable types, anonymous methods, iterator blocks and some other more minor features
C# 3, introducing implicit typing, object and collection initializers, anonymous types, automatic properties, lambda expressions, extension methods, query expressions and some other minor features
Read the rest here: http://csharpindepth.com/Articles/Chapter1/Versions.aspx

Basically:
.NET is a programming environment including, among other things, a virtual machine (the CLR) and an extensive class library (the BCL)
C# is a programming langage that targets the .NET environment. It is compiled to IL (a kind of assembly language executed by the CLR), and uses the classes from the BCL

The information HERE might be helpful to you.

C# is a programming language, very similiar to c++.
.NET is a set of libraries, classes, ready to use methods etc.
It is strictly related to C#. You use them both without noticing it :)
Every 'using' statement imports a set of classes to your project from .NET.

As Chevex says .NET is a framework and C# is just one of several languages targeting the framework.
Not sure about what you mean about "SP2" and VS2010. The language features you use will determine what version of the framework is required on the clients running your code.
See here for more information:
http://msdn.microsoft.com/en-us/library/bb822049.aspx
http://msdn.microsoft.com/en-us/library/8z6watww.aspx

Related

Is using polyfills to run C# v8 to v11 pattern matching functionality on .NET Framework 4.8 a solid idea?

I would love to use the more advanced pattern matching functionalities that c# version 8 through 11 offer in a .NET Framework 4.8-based solution (which only goes up to c# 7.3 by default).
I see that there are now automatic polyfilling solutions to achieve this very easily! Before I embark in this direction, I wonder if this is a solid solution or is there a good reason why this may lead to instability and weird behavior of the software I'm building (an Office VSTO solution hence the limitation of .NET Framework 4.8 as the highest possible version).
As a developer with limited insight in to what Visual Studio 2022 and its compiler are doing in the background I do not have adequate insight in to whether this could potentially lead to significant issues or not. Thank you for sharing your insights!
You most likely will still need to set LangVersion for this to work. This itself will be sufficient to enable some of the newer c# features, including pattern matching I think. I have not used PolySharp, but it looks like it just adds some types to enable as many features as possible.
To make this work the compiler has to be able to compile the code to regular .net framework code. I.e. the available features will be of the "syntactic sugar"-kind. Some features will require runtime support, and will not be available unless you update to a newer runtime. So things like generic math will not be available 😢.
Changing langversion is not officially supported. But I have used the latest lang version with .Net 4.8 for about three years now without encountering any issues, but I'm still on VS 2019. In the end it will depend on how risk averse you are.

Can C# apps run without the .NET framework?

I intend to learn C# and start coding Windows .exe applications, but the only thing that is holding me back is that not all potential users have the .NET framework installed and therefore would be unable to run my application.
Is there any way around it?
Thanks!
No. c# only target .NET (or a comparable framework, such as mono). As an aside, Win7 comes with .NET preinstalled, and I believe Vista did as well. There are also a ton of MS apps which require .NET. It's getting near ubiquitous on windows machines, so I wouldn't worry about it.
YES, there was XenoCode that can wrap everything that your app needs and runs it in as a standalone. I don't know what kind of dirty tricks they use, but there IS a way.
Now it's Spoon
From their site:
Spoon Studio
Easily virtualize all of your applications for instant,
zero-install delivery on Spoon Server and Spoon.net.
Spoon Studio lets you convert your existing software applications into virtual applications
that run with no installs, conflicts, or dependencies.
BTW, I'm in no way affiliated with them - just curious if the community will accept it or flame it.
Yes, with .NET Native.
Instead of compiling to intermediate language, it will compile to native code and run with statically linked .NET libraries. Therefore, there will be no .NET Runtime requirements for end users.
https://msdn.microsoft.com/en-us/vstudio/dn642499.aspx
https://msdn.microsoft.com/en-us/library/dn584397(v=vs.110).aspx
Does not work before Windows 10
C# is just a programming language. From a strictly technical point of view, someone could develop a C# compiler that targets the Windows API or <insert your target platform here> directly. Sure, it would be a lot of effort because C# was designed to fit .NET, which means the compiler writer would essentially have to re-implement .NET to provide all C# features.
From a practical point of view, you just want to use C# to target either .NET or Mono.
Microsoft started shipping .NET 2.0 with XP since 2005. So, even if your target machine was bought somewhere within the last 8 years, it should still have .NET.
If you are targetting the linux machines on the other hand, there is the mono framework available for that. You don't even have to include it, most repositories like ubuntu, debian, etc. has packages available for mono in their repositories. All you have to do is make your own package dependent on Mono runtime.
NO as simple as that
Everybody might say that it is already installed/ or you need the runtime. But that means YOU NEED IT
It's not about C#. It's about whether you want to develop managed or unmanaged applications. C# is the choice for developing managed applications which run on .NET Framework.
If you want to avoid it, you can go to Visual C++ (without .NET) development using Visual Studio
However, .NET framework comes pre-installed with latest Os like Win 7 these days.
Microsoft makes a redistributable installer that installs the version of .NET that you require. It bloats your install, but it's pretty much the only way to do what you need.
You'll need the .NET Runtime. However, most of the PCs running windows already have it.

When do I need the Windows SDK and what is .NET for?

I am a student and after taking some introductory programming courses in Java, C, and just finishing up a book on C++, I would like to start developing applications for Windows.
I have done my best to page through google and find the answers I need, but I seem to be at a loss.
When would I need the Windows SDK over just the regular API?
And what is .NET and why would I need it?
What is so special about C# and should I use that over C/C++?
When would I need the Windows SDK over just the regular API?
The SDK includes headers, libraries, tools, etc., that give you access to the API (and to .NET, for that matter). For example, a typical API-based program will start with #include <windows.h> -- but without the SDK, you don't have a copy of Windows.h to include. Likewise, the SDK includes the compilers (the same actual compilers included in the current version of Visual C++), linkers, debuggers, etc., necessary to actually build an API-based program.
And what is .NET and why would I need it?
.NET is a couple of things: a virtual machine that executes code in what Microsoft calls "intermediate language" (IL). It's also a (large) library of code in IL for everything from window management and drawing to communications, system management, etc.
You'd need it primarily if you were writing code in a .NET-based language such as C#, VB.NET, etc.
What is so special about C# and should I use that over C/C++?
C# is (by far) the preferred language for .NET development. Microsoft did develop .NET versions of Visual BASIC, and something at least quite similar to C++, but both tend to lag behind C# (at best).
So, if you're developing code specifically for Windows (especially if it includes a GUI), C# is probably your first choice. Microsoft does a lot more to support it than to support C or C++. That shows up in better support in both libraries and tooling.
The primary argument in favor of using C or C++ would probably be that you're developing primarily for Linux, and then porting the code to Windows. You can still do such development in C# if you want to (e.g., you can run C# and .NET under Linux using Mono), but especially if you're doing the development work under Linux, you lose most of the advantages.
On the other hand, if your code doesn't involve a GUI anyway, you might be able to write portable C or C++, and just compile it under both Windows and Linux. In such a case, using C# could involve extra work, such as having to install Mono to run the code under Linux--not a terribly difficult task, but even a fairly easy installation can be more work than no installation at all.
Windows SDK is a low-level framework for developing applications specifically for Windows. You could use it for your development. However, the APIs are low-level and a little difficult to use and maintain.
Alternatively, you could use .Net. .Net is a framework that includes runtime support for your application. It has many packages, I am sure you will find something useful in .Net. .Net needs a runtime for executation and is not compiled natively to the platform. However, it is easier for software development mostly because the APIs are higher level.
C# is the recommended language for Windows specific programming, specially on .Net. Not that it is the only language, you could also use C/C++, but they are not supported by Microsoft actively. For example, if you use C#, creating a GUI application could just a few mouse clicks. Using C++, you would need to manage your windows instances.
Typically, you would only use C/C++ for Windows programming if you are doing cross-platform programming or some low-level stuffs.

Is it C# or C#.NET?

I always see people writing "C#" and "C#.NET". What is the correct name of this language? C# or C#.net? I'm sorry for this stupid question but it is really confusing (maybe there's another programming language named C#.net?)...
EDIT: if I'm programming against the .NET Framework, why call this C#.NET? Can I use the C# language with other frameworks?
C# is a language, .NET is platform.
There are lot of languages on .NET: C#, Visual Basic, IronRuby and more.
wiki
The other answers are close but not quite right.
C# is the language, it is specified in an ISO standard.
.NET is the platform from Microsoft.
Visual C# .NET was the name of the developer tool in 2002. The name was shortened to "Visual C#" with the 2003 release. The more popular, expansive cousin is "Visual Studio". Subsequent to 2003, Microsoft dropped the independent commercial product called "Visual C#" (along with Visual Basic .NET) and introduced the free Express products. The current version is called Visual C# 2008 Express Edition, some people call it "Visual C# Express" for short.
In the same way, there is C++, and there is "Visual C++". The former is a language, the latter is a tool from Microsoft that you can use to write/compile/test/debug apps in the language, on Windows. (But again, most people use "Visual Studio" , which includes all the capabilities of Visual C# and Visual C++)
Basically,
C# is the language you're programming in.
.NET if the framework you're programming against.
The combination is C#.NET. There's also VB.NET, C++.NET, for when you're programming in VB/C++ against the .NET framework.
The language is C#, and the framework/platform it runs on is .NET. C# is purely a .NET language, there is no variant of it that is targeted on another platform, unlike for instance Visual Basic (this is why VB and VB.NET can mean different things).
But C# is always "C#.NET" and is called just C#.
When people say they are using "C#.Net", they mean they are developing on the .Net platform while using C#
"VB or VB.NET" makes sense as there are both .NET and non-.NET versions of the language. It does not make sense with C# because there is only a .NET version.
Similar with ASP and ASP.NET. The non-.NET version is usually called "Classic ASP."
I've never heard the C# language referred to as "C# .NET" but I guess you could reasonably use that term (even if it's a little redundant.)
So don't worry, there is only one C# language.
The C# language is only used with the .NET Framework. So when people say C#, it always means C# on the .NET Framework. Since C# isn't used with any other frameworks (as of writing this) the .NET in C#.NET is redundant.
Visual Basic on the other hand can either be the old VB Runtime or VB.NET. So VB needs the .NET qualification so you really know what you language you are really talking about because VB 6 and VB.NET are pretty different.
When I hear someone say C#.NET, it is usually from someone who isn't a programmer. Most recruiters see .NET appended to things like VB, Visual Studio and ASP, so they naturally append it to C# because for them, it is easier to just think everything is .NET.
There was a time when the marketing guys at Microsoft were sticking the suffix ".NET" on to every MS product they could. Sometimes it made sense - e.g. to distinguish VB 6.0, and earlier versions, from what came after. Other times it was just marketing phooee; at one point I think they were going to rechristen all the server products with the .NET suffix: Windows.NET Server, SharePoint.NET Services etc.
But it was a short-lived phenomenon and quickly dropped (in some cases before the products were actually launched).
In the case of C#, there was no earlier version and only later the prospect of publishing the spec and seeing other implementations, so it made little difference whether it was called C#.NET or just C#.
I guess that's just marketing guys for you - they did exactly the same with the "Active" prefix before that...
The language is C#. C# is also a popular language on the NET platform, so people often say C#.NET. The same thing used to happen for C++, where people would call it Visual C++. In both cases, what they really mean is C# using .NET and C++ using MFC.
C# is language. But it's always C#.net because C# language added to the Visual Studio Family when the Visual Studio.NET released.
In Visual Studio 6, C# was not there.
In Visual Stuio .NET in 2002/2003, C# was introduced.
".NET" for the general branding for VS 2002. So it was attached to everything related to it also "C#" is always-dotnet by it's nature.

How to run C# project under Linux

Do you know any ways to run a C# project under Linux. Are there any framewoks or libraries for this?
You're looking for the Mono Project - a cross-platform (but primarily targeted at Linux) implementation of the .NET Framework and CLR. It's capable of running binaries compiled for the CLR (MS .NET), or of creating its own native Linux binaries.
The project has been going a while now, and it's current version (2.4) is very usable, even for production purposes. See the project roadmap for details of the main features and milestones of current and future releases.
Details about the current state:
The great majority of the BCL (Base Class Library) is available on Mono, with the exception of some of the .NET 3.0/3.5 stuff, such as WPF (which has minimal support currently) and WCF (almost non-existent support). Silverlight 2.0 is however being supported via the Moonlight project, and progress on that is going well. WinForms functionality (which uses GTK# as a backend) is however quite complete, as far as I know.
Implementation of the C# 3.0 language is effectively complete, including the C# 3.0 features such as lambda expressions, LINQ, and automatic properties. I believe the C# compiler is mature to the point that its efficiency is at least comparable with that of the MS compiler, though not yet matching it in some respects. What's quite cool (and unique) about the Mono C# compiler is that is now offers a compiler service - in other words true dynamic compilation from code (without using the CodeDOM). This is something that MS will perhaps only add in .NET 5.0.
Like others have already said, you can run .NET applications on Mono. If your applications use Platform Invocation (P/Invoke) to call native code, you may run into some trouble if there is no Mono implementation of the native library. To check whether your application does that (or uses APIs that haven't been implemented in Mono yet), you can use the Mono Migration Analyzer (MoMA).
For those who come across this question post 2016, can use .NET Core - An open-source, general-purpose development platform maintained by Microsoft and the .NET community on GitHub. It's cross-platform (supporting Windows, macOS, and Linux) and can be used to build device, cloud, and IoT applications.

Categories