Welcome to your first step in learning and understanding the C# programming language. Interestingly enough, the first thing you need to understand actually has nothing to do with the language itself. In order to fully understand what you are getting yourself into, you need to take a step back and understand the landscape and that involves understanding the difference between C# vs .NET.
Throughout this post, I’m going to dig into this concept of C# vs .NET so that you can not only understand the difference between the two, but also get a good feel as to how these two concepts work together to create a wonderful development experience.
Finally, in the end, I will give you the most important reason that you need to understand the difference between C# vs .NET. But before we get ahead of ourselves, let’s start at the beginning of the story.
Congratulations on Your Choice
I have to say that I’m very happy that you have chosen to learn C# as either your first, or next, programming language. C# was the first programming language that I dove headfirst into and learned on my own. And since those early days…
I have never looked back!
Sure, over the years I have learned other languages, but I feel that it was C# that truly helped me form the foundation of my programming knowledge and, ultimately, my career.
Knowing what a wonderful experience this has been for me, I want to do my best to help ensure that you have a positive journey into learning to code with C#. That being the case, you are going to need to understand some basics.
When I first started learning to write C# code, the following concepts were rather difficult for me to understand. So let’s take this nice and slow and build a strong foundation.
C# is a Programming Language
In an effort to better understand the difference between C# vs .NET, let’s start with the first part.
What is C#?
C# is a programming language. Actually, I could make the argument that C# is THE programming language when it comes to Microsoft and it’s plans for the future. But I’ll save that conversation for another day.
What is a Programming Language?
Great! So C# is a programming language. But what exactly is a programming language?
A programming language is a formally defined set of keywords and expressions that can be combined to define instructions. These instructions are ultimately executed by a “computer” to produce some form of output.
In the previous sentence, I mention “computer” in quotation marks, because with today’s technologies, many non-traditional “computers” can run code written in many languages including C#. These could be cell phones, watches, and many other devices.
When you take these special keywords and instructions and combine them together in a special, formally defined, structure you get a program. And in the world of programming, this specially defined structure is known as a syntax.
I know that seemed like a lot of $100 dollar words jammed together in just a few sentences. But it’s important that you begin to get acquainted with this terminology. It’s going to become increasingly important over time if you are going to continue to learn and be able to have meaningful conversations and ask questions about C#.
The $10 Version
OK, so I can’t just leave you with all of that jargon. Here is the simplified explanation for pennies on the dollar.
Think of C# like the language that you speak. Since I am writing this post in English, we are going to use that as an example.
In a previous post on how to learn to write code, I used the example of explaining an idea to a 5 year old. So, let’s revisit that idea.
Imagine you are in the bathroom and become horrified by the fact that there is no more toilet paper! Your only hope, is your 5 year old niece that is at home with you.
If you don’t have a 5 year old niece, either pretend you do or some other young person that you know.
In order for you to “save your dignity”, you need to get your niece to go to the linen closet and get a new roll of toilet paper for you. Imagine the words you would use to get her to accomplish this goal.
The words you are putting together to convey an idea, or instructions to your niece, is like the C# language. Each individual word you use has its own meaning. When you string those words together in a certain order, with a certain structure, they become instructions that your niece can follow.
That is a programming language.
Each language uses different words and a different structure. But the basic idea is the same. You want to use a method of communication, with a computer, to get this computer to do something for you.
.NET is a Framework
Let’s not get to caught up in words again. Let’s just agree, for the sake of argument, that you have never seen the word “framework” before when referring to computers and programming. Even if you have, pretend you haven’t.
Let’s break this apart one piece at a time.
It’s Just Software
Let’s start at the most basic definition.
.NET is a framework. To be more specific, it’s name is actually the .NET Framework. And, the .NET Framework is software.
Just like any other piece of software that runs on your computer, in many circumstances, you need to install it.
Think of any other program you have ever installed on your computer or a game that you have installed on your cell phone. Those are examples of software. So is the .NET Framework.
It’s a piece of software that you install on your computer. And then…well…
It kinda just sits there…
You, but we will get there.
At this point, you just need to know that it’s software and it contains 2 very important things
- A Runtime
- A Class Library
Let’s take a look at these individually.
It Contains a Runtime
Yes, it contains a runtime. Actually, it contains the Common Language Runtime, or CLR. And these 3 little letters are probably the most important part of the .NET Framework. Without them, there would be no .NET Framework.
The CLR is what actually makes the .NET Framework…work.
When you create an application with a .NET Framework compatible language, like C#, that application runs on the CLR. Another reason why it is called a “runtime”.
The CLR knows how to run, or execute, applications that are written in C#. This is another reason why you can now use C# to write applications that can not only run on Windows, but also on Mac OSX and Linux.
But we will get to that in a few minutes.
It Contains a Class Library
Just like the .NET Framework contains a specific runtime, the Common Language Runtime, it also contains a class library. Actually it contains a specific class library.
The Framework Class Library, or FCL.
More $100 words.
Let’s break this down a little bit more.
We have already touched on this a little bit already. In the case of the FCL, the Framework really is just referring to the .NET Framework that it is a part of.
The idea of a class is going to take a little more effort to understand. Let’s get a little logical here.
In programming terms, a class is a logical unit that contains different pieces of reusable functionality.
Yes, there is more to it than that. But this is where we are going to start.
Let’s use an example.
Let’s say we have a “calculator class”. This class represents a calculator and everything that a computer is and can do. This class has code in it that knows how to do mathematical operations like add, subtract, multiply, and divide.
Not only does this class contain all of this functionality, but we, as programmers, can use that functionality so we don’t have to write out own code to do those operations.
Yay!!! Code we can use, but don’t have to write!
No, we aren’t talking about a collection of books here. But we are talking about a collection of something.
Let’s revisit the calculator example.
Let’s call this first calculator a “simple calculator”. Let’s also say that we have other calculators that know how to do complex operations that would be useful in geometry, algebra, and calculus. If we were to bundle these classes (think calculators) together, we would have a library.
So, quite simply, a class library is simply a collection of logical code units (classes) that have a bunch of pre-written code in them that we can use and don’t have to write from scratch.
Bring it All Together
Wow! That was a lot to take in. Let’s bring it all together one more time in an easily digestible list:
- C# is a Programming Language
- A programming language is a pre-defined collection or words that can be grouped together to give instructions to a computer.
- The .NET Framework is just software
- It *usually* needs to be install on your computer
- It contains 2 very important parts
- Common Language Runtime (CLR)
- This knows how to run applications written in a .NET Framework compatible language, like C#
- Framework Class Library (FCL)
- A collection of pre-written code that we, as programmers, can use to write different types of applications so we don’t have to write a lot of the basic functionality from scratch
- Common Language Runtime (CLR)
Save that. Write it down. Copy it to your computer. Bookmark this page. Do whatever you have to in order to remember this information. It will come in handy down the road.
Why is .NET Important for C#
Now that you have a basic understanding of the difference between C# vs .NET, let’s take a look at why the .NET Framework is so important for C#.
Based on the previous section, you already know that the .NET Framework contains lots of useful functionality that we can reuse in our applications without having to write some of that basic code.
Code reuse is awesome and very important.
But that isn’t the only reason the .NET Framework is important.
As part of the .NET Framework, the CLR is a layer that runs on top of your operating system whether it is Windows or Mac OSX and Linux. The Max OSX and Linux requires a little more explanation that we will cover shortly.
Not only does it run on top of your operating system, it also know how to interact with your operating system. This is incredibly important because it saves you TONS of work.
The .NET Framework Hides Complexity
Let’s say you want to create a desktop application on Windows. The .NET Framework contains a series of Class Libraries in the FCL that know how to translate C# language concepts into instructions that your computer can understand and execute in order to show windows, and other user interface components, to the user.
This is important because C# is what’s known as a high-level programming language that has no idea how to do things like draw windowed applications on the Windows operating system.
And the nice thing is that you don’t need to know that either.
You can do much simpler things like use C# to tell the .NET Framework to create a ‘new Window()’ and it will show up on the screen. But in reality there is a lot that goes on behind the scene.
For example, if you want to help yourself sleep at night, or maybe make your eyes bleed, take a look at what it takes to create a simple window in a low-level language that runs almost directly on the operating system, like Assembly.
There is definitely something cool and poetic about this, but that is definitely not the type of thing that I got into computers to have to write.
But if you are interested in going that deep, good for you!
I stay up in the clouds with high-level languages and that is just fine with me.
Variations of the .NET Framework
One last topic that I feel is important to touch on at this point has to do with something I have been alluding to at different points of this post. That is the different versions of the .NET Framework.
Yes, since its inception, the .NET Framework has gone through many numerical versions. It was initially released in 2002 with version 1.0. At the time of this writing you can head over to the download page and download version 4.7.2.
Over the years the .NET Framework has continued to evolve and contain more feature rich and powerful functionality. And it keeps getting better and better.
But there is a problem.
The .NET Framework ONLY works on Windows machines. This has been a problem for years and have caused many developers to stay away from it.
That is until now.
And now for for my favorite and the most important reason to understand the .NET Framework and why it is different from the C# programming language…
Enter .NET Core
Microsoft’s answer to the “only on Windows” issue came in 2016 with it’s release of .NET Framework Core, or just .NET Core.
This was a simpler, stripped down version of the .NET Framework, that could run on Windows, Mac OSX, and certain distributions of Linux.
This became a whole new world for Microsoft, the .NET Framework, and the C# programming language. Now C# developers could write applications in a single language, that they already knew, and have “most” of their applications run on multiple platforms. Not just Windows.
I say “MOST” applications because there are still limitations. For example, you can create web applications in C# that will run on Windows, Mac OSX, and Linux. But you can’t create desktop, windowed applications on Mac OSX and Linux…yet.
But this is still a HUGE step in the right direction!
When it comes to understanding the difference between C# vs .NET, it’s actually more important to understand how they work together. This is truly an example of trying to compare apples to oranges. So instead of trying to understand how they are different, you should really try to understand how they play together.
Remember, C# is a programming language that allows you to write applications that can run ON the .NET Framework. So, these two things actually work together to provide a very powerful environment on which you can create any sort of application imaginable.