In this series, we are going to discuss C# (pronounced as C Sharp) and the .Net framework. First of all, you have to make a clear distinction between C# and the other family of “C” languages like C, C++ and Visual C. While C++ can be considered as a successor of C, and has introduced a lot of new features, C# is a completely different brand. It is not an “enhanced” version of another language, it is a relatively new one built from the ground up by Microsoft. It is dependent on the .Net framework.
So what is .Net framework anyway?
Despite the name, .Net should not be considered an “Internet” or “Network” related programming framework only. Microsoft used this name to emphasize its belief of distributed applications, where processing is distributed between the client and the server.
Think of .Net as a set of classes that simplify a lot of the developer’s most common work. Database connections, network and disk access, security and authentication, and other common tasks used to cost developers a lot of time and effort. In another language (like C for example) you may need to write dozens of lines of code to achieve a – rather – trivial task like connecting to a database or loading a file from the disk. .Net provides ready-made classes that will do all the heavy lifting for you and let you focus more on the business logic of the application you’re building.
And what makes C# stand out?
There are a lot of languages that work under the .Net framework, and enjoy the classes it provides. Visual Basic .net, F#, J# and JScript.net are a few of them (you can view the full list here https://en.wikipedia.org/wiki/List_of_CLI_languages). So is C# that popular? And why would you need to learn it if you want to build modern Windows applications? For the following reasons:
- Easy syntax: C# syntax is very similar to very popular languages like C, C++, and Java. So if you are coming from one of those languages, you’ll feel right at home. Even if you are new to programming, you’ll find C# syntax easy to grasp.
- Large community: When you start working with the language, you will be amazed by the huge community support online. A lot of people are using the language and a lot of them are willing to help. Finding a solution to a problem in code, no matter how trivial or difficult it is, will very likely already exist online.
- Build all sorts of apps: Some languages (like PHP) are more suited towards web programming. They excel in their main domain – web applications – and fall short in other domains, like desktop applications, forcing you to learn other languages for those domains. With C#, you have it all under your belt. Learn one language and build almost any sort of application: Desktop, Web, or Mobile.
- Internationally-Standardized: C# has been approved by the International Organization for Standardization ISO (ISO/IEC 23270:2006)
How can I start coding in C#?
It is worth noting that C# is a “Windows” language. This means that it works only on Microsoft Windows platforms. Although a lot of attempts have been made to port the language to other platforms (like Linux for example), C# is still regarded as a Microsoft language. That being said, in just two steps you will be able to start building applications in C#: Download the .Net framework, and download an IDE.
Downloading the .Net framework
The current version of .Net framework at the time of this writing is 4.6, but we’ll stick to 4.5.2. You can directly download it from this link http://www.microsoft.com/en-us/download/confirmation.aspx?id=42642
Double click on the file and follow the instructions.
Downloading an IDE
IDE stands for Integrated Development Environment. It is a very rich code editor that not only provides code highlighting and syntax coloring, but also offers a lot of other features like debugging, a local web server, and many others.
Microsoft Visual Studio is the de facto IDE for working with C# and other .Net languages. It is not free, however, Microsoft offers a “community edition” that does not contain all the bells and whistles of the full version but it is more than enough to learn the basics and the advanced features of the language. The latest version of the IDE, at the time of this writing, is Visual Studio 2015, you can download your copy from this link https://go.microsoft.com/fwlink/?LinkId=532606&clcid=0x409
** Note ** Installing Visual Studio IDE automatically installs the appropriate .Net framework as part of the installation process. So, if you opted to use Visual Studio you don’t have to download and install .Net framework separately.
If you run the installer, it will download and deploy the IDE on your system. When prompted, choose “Typical” for the installation type.
Your first steps in C#
Start Visual Studio 2015, and choose File > New project. Choose Visual C# from the left pane and Console Application on the right pane. Name the application SampleApp01 as shown in the following figure:
Then inside the code window, write the code shown in the following figure:
Then press the start button with the green play symbol besides it to run your application.
And as you can see, a black console screen appeared with the text “Hello World” printed on it. Congratulations, you have just built your first C# application!!!
* * * * * *
In this article, we have knocked a new door to start learning another important programming language: C#
C# is a high-level, robust, object-oriented, and general-purpose programming language, which could be used to build all types of modern applications. It was developed by the World’s software giant: Microsoft. C# was designed to run natively on Windows platforms. It is dependent on the .Net framework.
To start coding in C#, you could either download the .Net framework or use command line tools to build your application. A third way is to download the fully fledged Microsoft Visual Studio, which installs .net automatically.
We have created our first C# application using Visual Studio. It printed “Hello World” on the screen. In the next article, we are going to explain its syntax in details.
That was part one in a long series of articles to come, so don’t miss one.
See you in the next article.