KodeBLOG

Kode Blog - Inspiring And Empowering Developers.

Home About Us Courses Categories Blog Contact Us

C# Tutorial

Introduction

This tutorial introduces you to C# programming language. It covers the basics that you need to know before you can start writing applications in C#.

Topics to be covered

  • What is C#?
  • Common Language Infrastructure (CLI)
  • Design goals for C#
  • What can C# do for you?
  • The future of C#

What is C#

C# pronounced as C-Sharp is a powerful and flexible strongly typed object oriented programming language. It was created by Microsoft. It is a general purpose programming language that is platform neutral. It is one of the languages in the .NET framework. C# can be used to develop;

  • Desktop Applications
  • Mobile Phone Applications
  • Console Applications
  • Web Applications
  • Others applications i.e. services, APIs etc.

The syntax for C# is similar to languages such as Java, PHP and other languages that were derived from C and C++.

The table below shows the programming paradigms supported by C#. A paradigm is a programming style.

Paradigm

Description

Strong typing

Variables have a static data type. Data type casting is done explicitly

Imperative

computations in terms of statements that change a program state

Declarative

computation without describing program control flow

Functional

computation as the evaluation of mathematical functions and avoids state and mutable data

Procedural

Series of computational steps to be carried out [routines, subroutines, methods etc.]

Generic

algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters

Object Oriented

concepts as "objects" that have data fields (attributes that describe the object) and associated procedures known as methods

Component Oriented

reuse-based approach to defining, implementing and composing loosely coupled independent components into systems

Common Language Infrastructure (CLI)

It is an open specification developed by Microsoft and standardized by ISO and ECMA that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework and the free and open source implementations Mono and Portable.NET.

C# is designed for the Common Language Infrastructure (CLI). The CLI is made up of executable code and the runtime environment. The CLI makes it possible to use multiple high level languages on different computer platforms without rewriting the code for specific platforms. The Common Infrastructure Language has two main components namely;

  • Common Intermediate Language (CIL)
  • Common Language Runtime (CLR).

The diagram below shows how C# interacts with the Common Infrastructure Language.

Tutorial Image

Design Goals for C#

According to Emac International C# Language Specification, C# has the following design goals.

  • The C# language is intended to be a simple, modern, general-purpose, object-oriented programming language.
  • The language, and implementations thereof, should provide support for software engineering principles such as strong type checking, array bounds checking, detection of attempts to use uninitialized variables, and automatic garbage collection. Software robustness, durability, and programmer productivity are important.
  • The language is intended for use in developing software components suitable for deployment in distributed environments.
  • Source code portability is very important, as is programmer portability, especially for those programmers already familiar with C and C++.
  • Support for internationalization is very important.
  • C# is intended to be suitable for writing applications for both hosted and embedded systems, ranging from the very large that use sophisticated operating systems, down to the very small having dedicated functions.
  • Although C# applications are intended to be economical with regard to memory and processing power requirements, the language was not intended to compete directly on performance and size with C or assembly language.

Why use C#?

  • It is easy to learn and use.
  • Allows you to develop applications rapidly due to its visual nature and built in function in the .Net framework.
  • Develop both desktop and mobile applications using the same language.
  • C# applications run on multiple platforms that include;
    • Windows
    • Mac OS
    • Linux based operating systems
    • Android
    • and many more

What can C# do for you?

  • Create components such as dll files, soap clients, user controls etc for other languages such as VB .NET
  • Create COM components that can be used in languages such as Visual Basic 6.0. This comes in handy when you have large systems developed in Visual Basic 6.0 and you have to port them to .NET
  • Since C# is a general purpose programming language, you can develop applications such as;
    • Network applications
    • Database Powered Applications
    • Windows services
    • Web services
    • and many more

The future of C#

C# is increasing becoming popular day by day and if you intend to major into a programming career then it wont hurt you learning it. It was named as the programming language of the year for 2012. C# is a standardized language and is slowly becoming the stand for developing windows based applications. Microsoft has continued developing the C# language and its fully supported on Windows 8. The current version for C# is 5.

Summary

  • C# is an object oriented general purpose programming language.
  • C# supports multiple programming styles
  • C# is designed for the Common Language Interface (CLI)
  • C# Code is compiled to Common Interface Language (CIL)
  • The Common Language Runtime (CLR) compiles Common Interface Language (CIL) into platform dependent executable machine code.
  • C# supports automatic memory management
  • The syntax for C# is C and C++ by inspired
  • Programs developed in C# include networking, database powered, desktop and website applications.

Tutorial History

Tutorial version 1: Date Published 2015-07-24