Introduction to C#
PREPARED BY:
PROF. ROCHELLE B. CADAYONG
What is C#?
❑ C# is a simple, modern,
general-purpose, object-oriented
programming language developed by
Microsoft within its .NET initiative led
by Anders Hejlsberg.
❑ C# programming is very much based on
C and C++ programming languages.
⚫ C# is a modern, general-purpose, object-oriented
programming language developed by Microsoft and
approved by European Computer Manufacturers
Association (ECMA) and International Standards
Organization (ISO).
⚫ C# was developed by Anders Hejlsberg and his team
during the development of .Net Framework.
⚫ C# is designed for Common Language
Infrastructure (CLI), which consists of the executable
code and runtime environment that allows use of various
high-level languages on different computer platforms and
architectures.
Reasons why C# is widely used
professional language.
⚫ It is a modern, general-purpose programming
language
⚫ It is object oriented.
⚫ It is component oriented.
⚫ It is easy to learn.
⚫ It is a structured language.
⚫ It produces efficient programs.
⚫ It can be compiled on a variety of computer
platforms.
⚫ It is a part of .Net Framework.
FEATURES OF C#
❑ Boolean Conditions
❑ Automatic Garbage Collection
❑ Standard Library
❑ Properties and Events
❑ Delegates and Events Management
❑ Easy-to-use Generics
❑ Indexers
❑ Conditional Compilation
❑ Simple Multithreading
❑ Integration with Windows
The .Net Framework
The .Net framework is a revolutionary platform that helps
you to write the following types of applications:
❑ Windows applications
❑ Web applications
❑ Web services
The .Net framework applications are multi-platform
applications.
The .Net framework consists of an enormous library of
codes used by the client languages like C#.
Example: C#, C++, Visual Basic, Jscript, COBOL
.Net Framework Components
❑ Common Language Runtime (CLR)
❑ The .Net Framework Class Library
❑ Common Language Specification
❑ Common Type System
❑ Metadata and Assemblies
❑ Windows Forms
❑ ASP.Net and ASP.Net AJAX
❑ ADO.Net
❑ Windows Workflow Foundation (WF)
❑ Windows Presentation Foundation
❑ Windows Communication Foundation (WCF)
❑ LINQ
Integrated Development Environment
(IDE) For C#
Microsoft provides the following development tools for C#
programming:
❑ Visual Studio 2010 (VS)
❑ Visual C# 2010 Express (VCE)
❑ Visual Web Developer
*The last two are freely available from Microsoft official
website.
Creating Hello World Program
⚫ A C# program consists of the following parts −
⚫ Namespace declaration
⚫ A class
⚫ Class methods
⚫ Class attributes
⚫ A Main method
⚫ Statements and Expressions
⚫ Comments
Take Note!
⚫ C# is case sensitive.
⚫ All statements and expression must end with
a semicolon (;).
⚫ The program execution starts at the Main
method.
⚫ Unlike Java, program file name could be
different from the class name.
Compiling and Executing the Program
⚫ Start Visual Studio.
⚫ On the menu bar, choose File -> New -> Project.
⚫ Choose Visual C# from templates, and then choose
Windows.
⚫ Choose Console Application.
⚫ Specify a name for your project and click OK button.
⚫ This creates a new project in Solution Explorer.
⚫ Write code in the Code Editor.
⚫ Click the Run button or press F5 key to execute the
project. A Command Prompt window appears that
contains the line Hello World.
C# Comments
Comments are used for explaining code. Compilers ignore
the comment entries.
The multiline comments in C# programs start with /*
and terminates with the characters */ as shown below −
/* This program demonstrates The basic syntax of C#
programming Language */
Single-line comments are indicated by the '//' symbol.
For example,
⚫ }//end class Rectangle