Denis Panjuta
c# basics

C# was developed in the late 1990s after the launch of Java. Both languages have been instrumental in increasing public access to the internet. At that time, the internet was used in universities and businesses for emails and document storage and production. Many things we take for granted today.  

Software companies were starting to develop the concept of internet browsers. These languages were the first steps to exposing the internet to the world.  

Java was launched in 1995 by Sun Microsystems. It was developed with C syntax, was object-oriented and included the concept of virtual environments — the Java virtual machine.

Complete C# Masterclass

Last Updated April 2021

  • 281 lectures
  • All Levels
4.5 (12,342)

Learn C# Programming – WPF, Databases, Linq, Collections, Game Development with Unity. More than just the C# basics! | By Denis Panjuta, Tutorials.eu by Denis Panjuta

Explore Course

C# was launched in 2000 by Microsoft. It was designed to be a more modern version of C/C++ and has a similar syntax and an object-oriented approach. C# is a type-safe language and memory management is handled by garbage collectors. C# programs are portable in the same way C/C++ programs are. All these characteristics allowed new and experienced programmers to easily learn C#. Systems developed in C/C++ could be translated and modernized with C#.  

C# introduced standardized support for international languages. One of the most critical goals was to develop a language to build web browsers and applications. C# uses Common Language Runtime and the .NET framework, Microsoft’s virtual environment, to do this.

C# was not designed to compete with the size and speed of programs developed with C or lower-level assembly languages.

What is a virtual environment?

Imagine playing Tic-Tac-Toe on your computer. No internet connection or connections to other machines. You and a friend passing the keyboard back and forth taking turns, in the same room side-by-side. No connectivity and no virtual network.

Now connect your computer to another computer on a network — still in the same room. No internet connection. A virtualized version of the same game would allow each machine to share that game. Each machine has the same visuals and uses the mouse and keystrokes from both machines. This is 1980s universities and businesses. Lots of computers connected and hard-wired in local-area networks.

Introduce web programs and virtualization. A web browser allows the program to run on any machine in the world and the game can be developed to allow any number of people to join. The web browser is a virtual environment — unrelated to your PC or the machine the game is running on. It is self-contained.

This was an amazing period in computing history, opening the gateway to developing so many of the ideas and programs we use in our everyday lives.

Program structure and components

A C# program consists of the following components:

Namespace declaration

A namespace is a collection of classes. The program will be one collection. It will use other namespaces from the C# language or those developed by the programmer.

A class

A Class is how objects are defined. Take a car for example. A car is a physical object with attributes such as color, size, weight, and methods such as drive and brake. A class is an object defined with attributes and methods.

Class methods

A method is a block of code that identifies an object’s behavior. If the object is a circle, one behavior might be that it can change size or color.

Class attributes

An attribute is a descriptive characteristic of the class. 

Main method

The main method is the entry point for the class. Executing the class executes this block of code.

Statements and expressions

These are the lines of code in the class methods. All lines end with a semicolon ‘;’.

Comments

Text that is not part of the program used to explain what the program is doing. These are optional.

Example program

Let’s look at an example program — we can start with a simple Hello World.

The color of the text is important. When you write your code, you will use an IDE — a program editor — designed for C#. A common example is Visual Studio which is available for free.

            Blue                 C# language component

            Purple              Statements and expressions

            Red                  Comments

            Green              Text used with statements and expressions

Here is the sample program.

using System;
 
namespace MyHelloWorldApplication {
   class HelloWorld {
      static void Main(string[] args) {
         /* my first program in C# */
         Console.WriteLine("Hello World");
      }
   }
}

Let’s walk through these lines and understand what they are and how they are used.

Namespace declaration and usage

System — this class contains some of the most fundamental classes and methods used in a program. It is almost universal that all classes use System.

MyHelloWorldApp — the class for this program defined by the programmer. Notice that it has an open curly bracket — there is an associated close curly bracket at the end of the program. These denote the start and end of this namespace.

using System;
 
namespace MyHelloWorldApp {

Class

This line defines the class — the object processed. Like the Namespace, curly brackets identify the start and end of the class.

class HelloWorld {

Main method

This is the main method of the class executed. Again, note the use of curly brackets.

static void Main(string[] args) {

Comments

This is free-form text. This text can help guide a new programmer through the program.

/* my first program in C# */

Statements and expressions

This is a statement intended to write text on the screen. Console is a class in the System Namespace. WriteLine is a Method in that class used to output the text — Hello World — out to the console.

Console.WriteLine("Hello World");

Let’s look at this same program and expand it to include variables and classes. In this case we created a method to output the text to the console. 

As programs get more complex, programmers write methods to execute discrete actions. Imagine the class was a circle — we could write methods to change the color or make it spin. A key component of programming is determining what to put in a method. Code once, execute many times.

Notice the indentation. The indentation makes the program more readable. When to use blank lines? Does each class have a comment at the top describing the class? Programming teams will start with identifying standards. When team members use the same standards, it is easy to support one another.

using System;
 
namespace MyHelloWorldApplication {
   class HelloWorld {
      static void Main(string[] args) {
 
         /* variable with text to output */
         string HelloText = "Hello World";
 
         WriteTextMethod(HelloText);
         WriteTextMethod("I am your friend!");
      }
      public void WriteTextMethod(string myString) {
 
         Console.WriteLine(myString);
      }
   }
}

This is a basic introduction to the world of C# programming. The language includes an amazing set of tools. C# is used to build desktop applications that run on Windows PCs and web applications and services. A real-time development platform called Unity allows C# applications to run on MACs. Unity is a host to an array of exciting and advanced applications including games and virtual reality experiences.

Top courses in C#

C# .NET For Beginners
Rick Phillips
4.4 (1,267)
What's New in C#7, C#8 and C#9
Dmitri Nesteruk
4.6 (566)
Complete C# Unity Game Developer 3D
Ben Tristem, Rick Davidson, GameDev.tv Team
4.7 (27,022)
Bestseller
C# Intermediate: Classes, Interfaces and OOP
Mosh Hamedani
4.6 (23,276)
Bestseller
RPG Core Combat Creator: Learn Intermediate Unity C# Coding
Ben Tristem, Rick Davidson, Sam Pattuzzi, GameDev.tv Team
4.7 (8,536)
Complete C# Masterclass
Denis Panjuta, Tutorials.eu by Denis Panjuta
4.5 (12,321)
Design Patterns in C# and .NET
Dmitri Nesteruk
4.4 (7,164)
Bestseller
Learn Parallel Programming with C# and .NET
Dmitri Nesteruk
4.5 (2,051)
Bestseller

More C# Courses

C# students also learn

Empower your team. Lead the industry.

Get a subscription to a library of online courses and digital learning tools for your organization with Udemy for Business.

Request a demo

Courses by Denis Panjuta

Der Unity 2017 & Blender Komplettkurs: Erstelle Top 3D Games
Denis Panjuta, Jannick Leismann, Tutorials.eu by Denis Panjuta
4.1 (495)
Highest Rated
Online Course Creation Masterclass - Udemy - Unofficial
Denis Panjuta, Tutorials.eu by Denis Panjuta
4.3 (18)
Complete C# Unity Developer: Create Games and Learn to Code
Denis Panjuta, Tutorials.eu by Denis Panjuta
4.3 (873)
Xamarin Forms: Erstelle Native Cross Plattform Apps mit C#
Denis Panjuta, Tutorials.eu by Denis Panjuta
4.1 (314)
Bestseller
Erstelle iOS Apps die geliebt werden
Codestars by Rob Percival, Denis Panjuta, Rob Percival, Tutorials.eu by Denis Panjuta
4 (746)
Erstelle einen 3D Jump and Run Plattformer mit Unity 3D
Denis Panjuta, Tutorials.eu by Denis Panjuta
4.4 (42)
Lerne großartige Webseiten zu erstellen
Jannis Seemann, Jan Brinkmann, Denis Panjuta, Jannis Seemann (CodingCourses.TV), Tutorials.eu by Denis Panjuta
4.2 (718)
Der ultimative Wordpress Kurs- dein Weg zur eigenen Webseite
Denis Panjuta, Tutorials.eu by Denis Panjuta
4.6 (32)
JavaScript und jQuery für Beginner
Denis Panjuta, Tutorials.eu by Denis Panjuta
3.7 (146)
Erstelle Android Apps, die geliebt werden!
Denis Panjuta, Codestars by Rob Percival, Tutorials.eu by Denis Panjuta
4.7 (895)
Highest Rated
Online Geld verdienen - Lebensunterhalt mit Videokursen
Denis Panjuta, Tutorials.eu by Denis Panjuta
4.2 (154)
Der Komplette Web-Entwickler Kurs - Erstelle 14 Webseiten
Denis Panjuta, Codestars by Rob Percival, Tutorials.eu by Denis Panjuta
4.4 (659)

Courses by Denis Panjuta