Introduction to C#

0
77
views
C#
Introduction to C#

A computer needs a set of instructions called a program to perform any operation. A program needs to be written in a specific language called programming language so that the computer can understand the instructions. C# is one such programming language.

This chapter introduces you to C#. It explains how to define classes and declare variables in C#. In addition, it discusses how to create the object of a class. Further, it discusses how to write and execute C# programs.

Objectives

In this chapter, you will learn to:

  • Identify C# basics
  • Declare variables
  • Write and execute C# programs

Introducing C#

Computer languages have come a long way since the 1940s. During that period, scientists punched instructions into large, room-sized computer systems.

These instructions were given in machine language, which consisted of a long series of zeroes and ones. These machine language instructions were executed directly by the CPU.

The machine language is called the First Generation of computer languages.
The 1950s saw the emergence of the Second Generation of computer languages, the assembly language.

Assembly language is easier to write than machine language but still
extremely complicated for a common man. However, the computer could still understand only machine language. Therefore, the Assembler software was developed to translate the code written in assembly language into machine language.

In 1967, Martin Richard developed a language called BPCL for writing operating systems. An operating system is a set of programs that manages the resources of a computer and its interactions with users.

The era of the Third Generation of computer languages had arrived. In
1970, Ken Thompson modified BPCL to create a new language called B. While working for Bell Laboratories, Thompson teamed up with Dennis Ritchie and wrote an initial version of the Unix operating system for a DEC PDP-7 computer.

Dennis Ritchie was working on a project to further develop the Unix operating system. He wanted a low-level language, like the assembly language, that could control hardware efficiently. At the same time, he wanted the language to provide the features of a high-level language, that is, it should be able to run on different types of hardware.

B had performance drawbacks, so in 1972 he rewrote B and called it C. Therefore, C is categorized as both a Second and a Third Generation language. Thompson and Ritchie rewrote the Unix operating system in C.

In the years that followed, C was widely accepted and used over different hardware platforms. This led to many variations of C. In 1989, the American National Standards Institute (ANSI), along with the International Standards
Organization (ISO), approved a machine-independent and standard version of C.

In the early 1980s, Bjarne Stroustrup of Bell Labs developed the C++ language. In his own words, “C++ was designed primarily so that my friends and I would not have to program in assembly, C, or various modern high-level languages.

Its main purpose was to make writing good programs easier and more pleasant for the individual programmer.” C++ was originally known as ‘C with classes’ because of two languages contributed to its design: C, which provided low-level features, and Simula67, which provided the class concept.

C++ is an object-oriented language. Other object-oriented languages are Java, Smalltalk, and C# (pronounced as C sharp). C# is a programming language introduced by Microsoft. C# is intended to be a simple, modern, general-purpose, object-oriented programming language.

The name C# is inspired by the musical scale. On a musical scale, sharp (#) written against a note means that the note should be made half step higher in pitch. This is similar to the name C++, where ++ appended to C indicates an enhanced version of the C language.

Introducing Compilers

All languages have a vocabulary, which is a list of words that have a specific meaning in that language. Languages also have their own grammar rules, which state the rules for combining words to form sentences.

This ensures that whatever is spoken in a particular language is understood
in the same way by all people who know the language. Similarly, programming languages also have a vocabulary, which is referred to as the set of keywords of that language, and grammar, which is referred to as the syntax.

Consider a scenario, where one person speaks in English with the other person. However, the person who is listening understands Chinese and not English. Therefore, he calls a translator who can translate the words of English to Chinese.

Similarly, computers cannot directly understand the instructions written in a programming language. Therefore, you need a translator to convert them
instructions are written in a programming language to machine language.

A compiler is a special program that processes the statements written in a particular programming language and converts them into machine language. Like everything else in the computer, the compiler also follows the Input-Process-Output (I-P-O) cycle.

It takes the programming language instructions as input. It processes these
instructions to convert them into machine language. These instructions can then be executed by the computer.

This process of conversion is called compilation. The following figure shows the working of a compiler.

C#
Working of a Compiler

For each programming language, there is a different compiler available. For example, to compile a program written in the C language, you require a C compiler. For a Java program, you require a Java compiler. For C# programs you will use the CSS compiler.

LEAVE A REPLY

Please enter your comment!
Please enter your name here