Home Programming Learn C# in 7 days

Learn C# in 7 days

By Gaurav Aroraa
books-svg-icon Book
eBook $35.99 $24.99
Print $43.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $35.99 $24.99
Print $43.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Day 01 - Overview of the .NET Framework
About this book
This book takes a unique approach to teach C# to absolute beginners. You’ll learn the basics of the language in seven days. It takes a practical approach to explain the important concepts that build the foundation of the C# programming language. The book begins by teaching you the basic fundamentals using real-world practical examples and gets you acquainted with C# programming. We cover some important features and nuances of the language in a hands-on way, helping you grasp the concepts in a fluid manner. Later, you’ll explore the concepts of Object-Oriented Programming (OOP) through a real-world example. Then we dive into advanced-level concepts such as generics and collections, and you’ll get acquainted with objects and LINQ. Towards the end, you’ll build an application that covers all the concepts explained in the book. By the end of this book, you will have next-level skills and a good knowledge of the fundamentals of C#.
Publication date:
October 2017
Publisher
Packt
Pages
306
ISBN
9781787287044

 

Chapter 1. Day 01 - Overview of the .NET Framework

This is Day 01 of our seven day journey to learn C#. Today, we will begin with an introduction of a new world of programming and will discuss all the basic concepts required to learn this programming language. We will also discuss the .NET Framework and the .NET Core framework by covering important concepts of the framework. We will also get a basic understanding of managed and unmanaged code. At the end of the day, we will start with a simple Hello World program.

Today, we will learn the following topics:

  • What is programming?
  • What is .NET Core?
  • What is .NET standard?
 

What is programming?


There might be various definitions or various thoughts to define the word programming. In my view, programming is writing a solution in such a way that a machine (computer) can understand to depict the solution, which you can identify manually.

For example, let’s say you have a problem statement: find the total count of vowels from this book. If you want to find the solution to this statement, what will you do?

The probable steps for the solution to this problem are as follows:

  1. First, get the right book. I am assuming that you know the vowels (a, e, i, o, and u).
  1. How many vowels did you find in a book?--0 (zero).
  2. Open the current page (initially, our current page is 1) and start reading to find vowels.
  3. If the letter matches a, e, i, o, or u (please note that the case doesn’t matter, so the letters might as well be A, E, I, O, and U), then increase the vowel count by one.
  4. Is the current page completed?
  5. If the answer of step 5 is yes, then check if this is the last page of the book:
    • If yes, then we have the total vowel count in hand, which is nothing but n, where n is the total number of vowels found in the current chapter. Move to step 8 for the result.
    • If this is not the last chapter, move to the next chapter by adding 1 to the current chapter number. So, we should move to 1 + 1 = 2 (Chapter 2).
  6. In the next chapter, repeat steps 4 to 6 and until you reach the last chapter of the book.
  7. Finally, we have the total vowel count, that is, n (n is the total number of vowels found).

The preceding steps just described how we reached a perfect solution for our problem statement. These steps showed how we manually found the answer to our problem of counting all the vowels in the book's chapters.

In the programming world, such steps are collectively known as an algorithm.

Note

An algorithm is nothing but a process to solve a problem by defining a set of rules.

When we write the preceding step(s)/algorithm in such a way that a machine/computer will be able to follow the instructions, it is called programming. These instructions should be written in a language understood by the machine/computer, and this is what is called a programming language.

In this book, we will use C# 7.0 as the programming language and .NET Core as the framework.

 

What is .NET?


While we are referring to .NET (pronounced as dot NET), it is .NET Full, as we have .NET Core in place and we are using .NET Core in our book examples with C# 7.0 as the language. Before moving ahead, you should know about .NET because there is a .NET Standard available with the .NET Core, that is API servers for both .NET Framework as well .NET Core. So, if you created a project using .NET Standard it is valid for both .NET Framework and .NET Core.

.NET is nothing but a combination of languages, runtime, and libraries, by using which we can develop managed software/applications. The software written in .NET is managed or is in a managed environment. To understand managed, we need to dig into how binary executables are available for operating systems. This comprises three broader steps:

  1. Writing the code (source code).
  2. Compiler compiles the source code.
  3. The operating system executes the binary executable immediately:

Broader steps – how binary executable is available?

The preceding process is a standard process depicting how compilers compile the source code and create executable binaries, but in the case of .NET, the compiler (C# compiler for our code) does not directly provide a binary executable; it provides an assembly and this assembly consists of metadata and intermediate language code, also known as Microsoft Intermediate Language (MSIL) or Intermediate Language (IL). This MSIL is a high-level language and this can’t be understood directly by the machine, as MSIL is not machine-specific code or byte code. For proper execution, it should be interpreted. This interpretation from MSIL or IL to the machine language happens with the help of JIT. In other words, JIT compiles MSIL, IL into the machine language, also called native code. For more information, refer to https://msdn.microsoft.com/en-us/library/ht8ecch6(v=vs.90).aspx.

For 64-bit compilation, Microsoft has announced RyuJIT (https://blogs.msdn.microsoft.com/dotnet/2014/02/27/ryujit-ctp2-getting-ready-for-prime-time/). In the coming versions, 32-bit compilation will also be handled by RyuJIT (https://github.com/dotnet/announcements/issues/10). After this, we can now have a single code base for both CoreCLR.

Note

Intermediate language is a high-level component-based assembly language.

In our seven days of learning, we will not focus on the framework, but we will be more focused on the C# language with the use of .NET Core. In the coming sections, we will discuss important things of .NET Core in such a way that while we work with a C# program, we should understand how our program talks with the operating system.

 

What is .NET Core?


.NET Core is a new general-purpose development environment introduced by Microsoft to meet cross-platform requirements. .NET Core supports Windows, Linux, and OSX.

.NET Core is an open source software development framework released under MIT License and maintained by the Microsoft and .NET community on the GitHub (https://github.com/dotnet/core) repository.

.NET Core features

Here are some important features of .NET Core, that make .NET Core an important evolution step in software development:

What makes .NET Core?

.NET Core is a combination of coreclr, corefx, and cli and roslyn. These are the main components of .NET Core composition.

What is .NET Standard?

The .NET Standard is a set of APIs that resolves the problems of code sharing while you’re trying to write cross-platform applications. Currently, Microsoft is working on .NET Standard 2.0 to make it streamlined, and these standards will be implemented by all, that is, .NET Framework, .NET Core, and Xamarin. With the use of .NET Standard (that is a set of APIs), you are ensuring that your program and class library will be available for all targeted .NET Frameworks and .NET Core. In other words, .NET Standard will replace Portable Class Libraries (PCL). For more information, refer to https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/.

Note

The .NET Standard 2.0 repository is available at https://github.com/dotnet/standard.

Till now, you've got an idea of .NET Core and a few other things that help build cross-platform applications. In the coming sections, we will prepare the environment in order to start learning the C# language using Visual Studio 2017 (preferably the community edition).

Available IDEs and editors for C#

Integrated Development Environment (IDE) is nothing but software facilitating the development of applications. On the other hand, editors are basically meant to add/update predefined or new content. When we talk about the C# editor, we are referring to an editor that helps write C# programs. Some editors come with a lot of add-ons or plugins and can compile or run the programs.

We will use Visual Studio 2017 as our preferred C# IDE; however, there are a few more C# IDEs and editors you can go with:

  1. Visual Studio Code: VS Code is an editor, and you can start by downloading it from https://code.visualstudio.com/. To start with VS Code, you need to install the C# extension from https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp.
  2. Cloud9: It is a web browser-based IDE. You can start it for free by signing up at https://c9.io/signup.
  3. JetBrain Rider: This is a cross-platform IDE by JetBrains. For more information, visit https://www.jetbrains.com/rider/.
  4. Zeus IDE: This is an IDE designed for the Windows platform. You can start using Zeus from https://www.zeusedit.com/index.html.
  1. Text editor: This is the way you can go without any installation; just use a text editor of your choice. I use Notepad++ (https://notepad-plus-plus.org/download/v7.3.3.html) and the Command Line Interface (CLI) to build code. Refer to https://docs.microsoft.com/en-us/dotnet/articles/core/tools/ to know more about how to start with the CLI.

There may be more alternative IDEs and editors, but they are not as important to us.

Setting up the environment

In this section, we will see step by step how to initiate the installation of Visual Studio 2017 (preferably, the community edition) on Windows 10:

  1. Start the Visual Studio setup.
  1. From Workloads, select the options you want to install. For our book, we need .NET desktop development and .NET Core:
  1. Click on Install to start the installation:
  1. Click Launch once the installation is completed.
  2. Sign up for Visual Studio using your Live ID.
  3. Select Visual C# as your development setting.
  4. You will see the start page as follows:

We are all set to start with our first step.

 

Hands - on exercises


Answer the following questions by covering the concepts of today’s learning.

  • What is programming? Write down an algorithm to find out vowel counts from all the pages of book, Learn C# in 7-days.
  • What is .NET Core and .NET Standard?
  • What makes a .NET Core an evolutional software ?
 

Revisiting Day 01


Today, we walked you through some important concepts of .NET Core and .NET Standard. You learned what programs and algorithms are in the programming world.

About the Author
  • Gaurav Aroraa

    Gaurav Aroraa has done M.Phil in computer science. He is a Microsoft MVP, life time member of Computer Society of India (CSI), certified as a scrum trainer/coach, XEN for ITIL-F and APMG for PRINCE-F and PRINCE-P. Gaurav serves as a mentor at IndiaMentor, open source developer, contributor to TechNet Wiki co-founder of Innatus Curo Software LLC. In 19+ years of his career, he has mentored thousands of students and industry professionals. You can tweet Gaurav on his twitter handle @g_arora

    Browse publications by this author
Latest Reviews (1 reviews total)
Desperately needs editing - what does this paragraph even mean? "...Before moving ahead, you should know about .NET because there is a .NET Standard available with the .NET Core, that is API servers for both .NET Framework as well .NET Core. So, if you created a project using .NET Standard it is valid for both .NET Framework and .NET Core."
Learn C# in 7 days
Unlock this book and the full library FREE for 7 days
Start now