Introduction To Programming C#

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

CSD 2354: Programming C#.

Net

Lecture 1
Objectives
• Introduce basic computing concepts
• The .NET framework
• Overview of C#
• The elements of a C# program
• Compiling and running C# program
• Developing a C# program
Introduction to Computing
• Hardware:
Introduction to Computing
• Software
– Programs the computer executes
– The OS provides an interface to the computer
hardware for us
– Businesses rely on computer software to serve
customers
Introduction to Computing
• Software
– Processor executes software using instruction sets
– Instruction sets are simple
– A simple task on the software may require many
lines of instructions
Introduction to Computing
• Each instruction has:
• operation (e.g., addition),
• operands (numbers to add) and
• memory numerical address (to store or retrieve data from)
• Each instruction performs a load, store or
addition
• Too many instructions for a simple task
• Same thing has to be repeated for another
different processor
Introduction to Computing
• High level languages allows us to:
– Combine several steps into one expression
– Write programs for many types of processors
• Compiler compiles high level language (source
code) and converts it into executable code
suitable for particular processor
The .Net Framework
• Microsoft developed the C# language along
with the .Net framework
• The .Net framework was designed to fulfill the
following objectives:
– Object oriented programming environment
– Code execution environment to minimize software
deployment and versioning conflict
– Code execution environment that guarantees safe
execution of code
The .Net Framework
– Code execution environment that eliminates the
performance problem of scripted or interpreted
environments
– To make developer experience consistent across
widely varying types of applications
– To build all communication on industry standards
so that code based on the .Net framework can
integrate with any other code
The .NET Framework
Two main parts
• Common Language Runtime (CLR)
– manages execution of code and
– provides services to make the execution of code
easier
• .NET Framework Class Library provides a
large set of types to speed up the
development process
The Common Language Runtime(CLR)
• Code that uses CLR are called managed code
– VB.Net uses CLR
• Common Type System
– defines the types of data that managed code can
use.
• Common Language Specification (CLS)
– defines features that every language for
developing managed code must provide
The Common Language Runtime(CLR)
• There are many different types of processors that
run code
• To work in the different types of devices you can
translate the program to the native instruction
set for that device
• The other approach, which is used by CLR:
– compile the source code into an intermediate
language
– during runtime the CLR uses a Just In time compiler to
compile the intermediate language code to the native
code of that device
The Common Language Runtime(CLR)
The Common Language Runtime(CLR)

Using an MSIL reduces the number of compilers from 9 to 6


The .NET Framework Class Library
• The library groups types into namespaces that
combine related types.
• There are about 100 namespaces.
• For example,
– System -- Contains fundamental types.
– System.Drawing - Provides graphics.
– System.Windows.Forms - For user interfaces in
Windows-based applications
Overview of C#
History
• FORTRAN and COBOL were among the first
high level languages introduced in the late
1950s
• The c language was developed in the mid
1970s.
• It is a high level language that provides access
to machine hardware
Overview of C#
• Object oriented programming started to
become popular in the mid 1980s
• Smalltalk, released around 1980, is a fully
object oriented language that influenced its
successors, including java and c#
• BASIC was developed in 1960s as an easier
way for students to learn to program
• BASIC soon morphed into Visual Basic and
became extremely popular
Overview of C#
• With the introduction of the .NET framework,
VB became VB.NET
• C# is described as a language that combines
the rapid application development of VB and
the power of C++
• Java was developed in 1995 and C# in 1999
C# Features
• Modern object-oriented language used for
building business objects or system
applications
• Important characteristics are:
– productivity and safety
– power, expressiveness, and flexibility
– C# allows low level access to machine resources
How C# works
• Compiler translates C# source to MSIL code
• During runtime the CLR use a Just-In-Time
(JIT) compiler to translate the MSIL code to
the instruction set of the processor
The elements of a C# program
/*Computes the square of a number
* Displays the result in a message
*/
public class Square
{
//execution starts here
static void Main()
{
int number = 345;
int squared = number * number;
System.Console.WriteLine
("The square of {0} is {1}", number, squared);
Console.Read();
}
}
Output : The square of 345 is 119025
Lexical Structure
• Rules for dividing program text into a
sequence of input elements
– Whitespace -- spaces, tabs, carriage returns
– Comment – for human readers only
– Punctuators ( ) { } [ ] ; , . :
– Operators + - * / and so on
– Literals – specific values such as 345
– Identifiers – the names used for program entities
– Keywords – reserved names for special uses e.g.,
public static void
int number = 345;

C# compiler lexical analyzer

keyword identifier operator literal punctuator

(int) (number) (=) (345) (;)

(whitespace and comment discarded)


class declaration

method declaration

statement

statement

statement

Figure 1.8 The overall syntactic structure of code


Syntax
• Grammatical rules for combining lexical
elements into programs
• C# Syntax includes:
– Declaration – defines a part of a program e.g.,
class
– Statements – controls execution sequence e.g.,
block of code to compute square
– Expressions – compute values (number*number)
Compiling and running C# programs
The key steps of Software Development

• Identifying the requirements of the system.


• Designing a system that meets the
requirements.
• Implementing the system.
• Testing that the system operates correctly and
meets the requirements.
• Making improvements as needed.

You might also like