Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

C# - Entry level Programming - 1


Recommended Posts

Welcome to the first entry of my C# programming guides. Through this tutorial I hope to provide you with enough knowledge to begin your adventure with the C# Programming language. I will be going over various entry-level programming topics through this thread and hope they will assist you with either learning the language or migrate to it from another such as VB, java or even C++.

Due to the amount of content I wish to cover over the duration of this series, I will be splitting the tutorials into various threads based on content. Once more than one entry to the series has been released I will create a "Master Index" thread with links to all entries in the tutorial.

Table of contents

1. Introduction to .NET
2. Getting Started - Visual Studio
3. Hello World

1\. Introduction
The C# programming language is a "high level" programming language built on the .NET framework; a platform provided by Microsoft to assist with rapid application development for Microsoft based platforms. With this being said it is still possible to use the C# programming language to develop for alternative platforms such as UNIX based OS and MAC OS X via the mono framework.

Over the years Microsoft (hence forth will be MS), has released various updates to the framework correcting bugs, adding features and updating features. For the purposes of these tutorials I will be providing code relevant for .NET 4.5.2\. Please note that this means some of the code will not be compatible with newer and or older versions of the framework.

So what is this framework?

Think of the .NET framework as a base for your programs. The framework provides us with numerous built-in features to assist with developing software for Windows base OS. In other words it's going to provide you with a quick way to complete tasks that may not be so quick in other languages. The .NET framework also provides us with other neat and nifty tools such as the JIT debugger, and CLR.

JIT; Just in time debugger allows provides an easy way for us to debug our code on the fly.
CLR; Common Language Run-time allows our code to be executed on any system with the correct version of the .NET framework.

However, when using the .NET frame and programming in C# there is a certain pipeline in which you program will follow in order to execute in which makes it different from a native language such a C++.

Below is a diagram of the pipeline in which your code will follow in order to execute:

![](https://www.codeproject.com/KB/dotnet/DotNetFramework/compilation.jpg)

It's pretty self explanatory however, for those of you looking at the diagram and thinking what does this mean I'll explain:

1) Code => The code in which you wrote for your program.
1.5) The compiler converts your C# code to MSIL code.
2) MSIL Code => Microsoft Intermediate Language Code; This code can then be executed through the CLR
2.5) CLR => Common Language Run-time allows our code to be executed on any system with the correct version of the .NET framework.
3) Native Code => The code in which tells the computer what to do. In other words these are lower level instructions in which were interpreted from your C# code.
4) Processor => Well we are really low level know and executing in machine code which is way beyond this tutorial series.

The only parts that are important for us to know about(as beginners) is 1- 2.5 really. In other words our code, the compiler, how our code is stored and then how it executes.

**References:**
https://msdn.microsoft.com/en-us/library/67ef8sbd.aspx (C# Programming Guide)
http://www.mono-project.com (Mono framework)
https://msdn.microsoft.com/en-us/library/bb822049(v=vs.110).aspx (.NET Framework Version Guide)

2\. Getting Started - Visual Studio
Before we can jump into coding and learning how to use C# to make our life's easier we must first setup our ide; integrated development environment of choice. In this tutorial series we will be using Visual Studio as it provides us with many useful features for debugging and compiling our code.

There are different versions of Visual Studio available for you depending on your needs however, assuming we are all personal hobbyist or education oriented the community edition will suit all of our needs just fine. You can access the latest version of the community edition directly on the MS website via the link below:
https://www.visualstudio.com/downloads/

**WARNING PLEASE ONLY EVER INSTALL VISUAL STUDIO FROM OFFICE MS WEBSITE OTHER SOURCES MAY CONTAIN VIRUS** Once you have downloaded the VS(Visual Studio) installer you will be prompt to select the tools in which you wish to install. You will want to select the Windows development tools sections as well as any Azure sections if you are looking to get into ASP.NET development at some point. Don't worry if you miss something or want to install more later, you can always upgrade.

![](https://i.gyazo.com/e9104a8b02cc63d64baee56c029caea2.png)

3\. Hello World
Now that Visual studio has installed you should be ready to begin your software development career. To make sure everything is setup correctly let's create a simple "Hello World" application.

To begin, open Visual Studio 2017\. This may take a few moments if this is the first time you've ever ran Visual Studio as it will need to setup the environment for you. Don't worry if it seems like it's not responding it's just busy creating files and setting defaults.

Once loaded, along the menu bar at the top please click "File->New->Project" or "Ctrl+Shift+" on your keyboard. This will open the new project dialog in which will provide you with various options depending on the .NET components you installed.

For the purpose of this tutorial you will want to find the "Console App (.NET Framework)" template under the "Visual C#" section.

It should look something like this:
![](https://i.gyazo.com/5a53a5038d4f9c156ec9e309b15a324b.png)

You may name it anything you want. I'll be naming mine "Hello World" and storing it under a folders on my D: drive. You can change where the project files are created and stored via the "Browse" button.

Once you are ready simply click "OK" and Visual Studio will begin setting up a new project for you.

At this point you should be brought to a new tab in Visual Studio in which you should see a bunch of code _automagically_ generated for you. Since this is only a hello world I've posted the code for this project on pastebin.

What we want our program to do is simply say "Hello World" on the screen.
![]([color][size]https://i.gyazo.com/172326ff02c35fb75b1cfd5b1c1b5a78.png[/size]

For this to happen a few things need to be done.

[/color]
[list]
[*][color]When the program is opened the operating system needs to find code [color]to run -> Main entry-point
[/color][/color]
[*][color][color]The code needs to somehow output a mess[color]age onto the screen for the user[color] -> [color]Command Prompt Window or Console Window in this case
[/color][/color][/color][/color][/color]
[*][color][color][color][color][color]Once the message is output, we [color]would [color]ideally like the window to stay o[color]pen so we can read[color] it -> [color]Pause the program from closing.
[/color][/color][/color][/color][/color][/color][/color][/color][/color][/color]
[/list][color]Something to keep in mind i[color]s that once your program [color]has finis[color]hed [color]executing all of it's code it will close by itself [color]as there is nothing left to do. Thus in our [color]program we are going to stop this from happening so that we may read the message on the screen.
[/color][/color][/color][/color][/color][/color][/color]

[color][color][color][color][color][color][color][color][b]Back to the list...[/b][/color][/color][/color][/color][/color][/color][/color][/color]

[color][color][color][color][color][color][color][color]The first thing we need to worry about is where our pr[color]ogram is going to start. This is called the )
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...