Start Learning Now!
-
Start with this free tutorial in the C# course
-
Learn the easy way in step-by-step stages
-
Getting stuck? Follow an in-depth video
-
Share on your community forum.
Exam Preparation
The C# course will help you prepare for these certifications:
-
MTA Developer (Technology Associate) – Software Development Fundamentals Exam 361
-
MCSD/MCSA Universal Windows Platform (Solution Developer) – Programming in C# Exam 483
Overview of this C# Tutorial
Estimated Time – 1 Hour
What is .NET?
- .NET is Microsoft's strategic platform for developing enterprise systems for the modern era.
- ASP.NET Web applications.
- Mobile applications.
- Console applications.
- .NET recognizes and addresses the traditional difficulties facing application developers.
- Language interop- VB6, VC6, ASP, WinSDK.
- Deployment difficulties - DLL's.
What new programming languages are offered in .NET?
- C# - Similar to Java and C++.
- Visual Basic - Like VB6 but an Object Orientation approach.
- C++/CLI - New keywords that allow you to write in C++ for .NET.
- F# - Functional programming language.
Why C#?
- Syntax more like C++ and Java.
- Syntax very concise.
- Designed for object orientation - Started with a clean slate, Everything is an object.
The goals behind C#?
- Simple - Few Keywords.
- Safe - Find bugs early in development process.
- Internet Centric - Designed for developing web programs.
- Hi Performance - Designed for industrial strength programming.
- Here are some example pieces of code for a Hello World application in C# and VB. First in C#, by creating the hello world application we hope to show you the key foundations of creating an application with the types of user interface in this case a form or a console that will be seen later in the course with their "code behind" files in C# that do all the hard work.
using System; public class CSHelloWorld { public static void Main(string[] args) { Console.WriteLine("Hello World!"); } }
- The second in VB.
Imports System Module VBHelloWorld Public Sub Main(ByVal args As String()) Console.WriteLine("Hello World!") End Sub End Module
- This code can be run from the Visual Studio 2013 command prompt window.
- Compile the code:
csc CSHelloWorld.cs
- Run the application:
CSHelloWorld.exe
- Compile the code:
- What is happening behind the scenes?
ildasm CSHelloWorld.exe
- Assemblies in .NET.
- An assembly is a .DLL or .EXE containing managed code E.g. CSHelloWorld.exe.
- You can create apps that contain (or reference) many different assemblies.
- To illustrate how assemblies work, we'll build a simple Windows Forms application in C#.
- Start Visual studio 2013 and Start a New project; Choose Visual C# and Windows Form Application.
- Drag the bottom right of Form1 to make it larger; and from the left hand side there is a navigation bar that contain a ToolBox Item. Click this, and as you can see there are many different controls that you can access. Drag and drop the control called button (found under common controls) onto Form1, you should see a button on the screen with the writing "button1" inside it.
- In the bottom right there is a properties table when you select the button, in this properties window set the "Text" attribute to "Click me for hello world". Re-size the button as you wish to make it larger or smaller by selecting and edge and dragging it out or inwards.
- To create an event for when the button is clicked, you can double click the button and Visual Studio 2013 will create an event handler for you automatically inside Form1.cs. Inside this handler use this code:
MessageBox.Show("Hello World");
- View code file.
- Now at the top of visual studio 2013 there is a button labelled Start with a green arrow inside it; click this when you want to run/debug your application. So click this and you will see your newly made form appear and when you press the button a message box will appear saying "hello world".
If you would like to see more content like this in the future, please fill-in our quick survey.