C# Chapter One

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

Event Drive Fundamentals

Prepared by Biruk Getachew


 Event-driven programming is a programming paradigm
in which the flow of the program is determined by events.
 That means, what a program does depends on what an
events have take place.
 During event driven program, code is executed upon the
activation of events.
 An event act as a trigger to make the program to do
something.
 Example: sensor outputs or user actions (mouse-clicks, key
presses) or messages from other programs or threads.
 Event-driven programming is a programming paradigm
where entities communicate indirectly by sending events
to one another through an intermediary.
 EDP is a programming where the overall flow of the
application is controlled by system, program or user
generated events.
 Event-driven programming allows to write code that
responds to specific events that are raised in application.
 Most of the programs are event driven programs, such as
GUI operating system(windows), spreadsheet etc.
 Event
 is a signal or message to the program that something
has happened, such as a mouse click on a graphical
button.
 It can be triggered either by external user actions, such
as:
 mouse movements, button clicks,
 key-pressing and the operating system.
 Then, the program can choose to respond to or ignore an
event.
 Event Handler
 An event handler is a program function that is executed
by the application or operating system when an event is
executed on the application.
 are an important concept a segment of code that is
executed in response to an event.
 An event handler is code associated with a particular
event, such as “button A pressed”.
 Create the association between an event and an event
handler by calling a function named “on “.
 After registering an event handler with an event, then
whenever that event occurs, the event handler code
executes.
 Different programming languages support Event-driven
programming to varying degrees. The following languages
have complete event support:
 C sharp
 Java
 JavaScript user actions
 Delphi programming language
 VB .Net and etc.
 C# Programming
 C# is one of the languages that used to create applications that will
run in the .NET Framework /. NET Core.
 C# is one of the newer programming languages. It conforms
closely to C and C++, but many developers consider it similar to
Java.
 C# is a modern, general-purpose, object-oriented programming
language.
 Developed by Microsoft.
 Approved by European Computer Manufacturers Association (ECMA) and
International Standards Organization (ISO).
 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.
 It has the rapid graphical user interface (GUI) features of
previous versions of Visual Basic, the added power of C++,
and object-oriented class libraries similar to Java.
 C# can be used to develop any type of software
component, including:
 Mobile applications
 Dynamic Web pages
 Database access components
 Windows desktop applications
 Web services
 Console-based applications.
 The following reasons make C# a 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.
 .NET Framework
 Framework
 The framework is a reusable design platform for software
systems, which provides support for code libraries and various
scripting languages.
 In simple words a framework is something that makes core
programming easy.
 .Net Framework is a software development platform for building and
running Windows applications.
 .Net framework includes developer tools, programming languages,
and libraries that are used to develop desktop and web applications.
 It is also used to build websites, web services, and games.
 The .NET Framework is a revolutionary platform created
by Microsoft for developing applications in the mid-1990s.
 .NET Framework generally consists of an environment for
the development and execution of programs, written in C#
or some other language, compatible with .NET (like
VB.NET, Managed C++, J# or F#).
 It consists of
 The .NET programming languages (C#, VB.NET, F#
andothers)
 An environment for the execution of managed code (CLR or
Common Language Runtime), which executes C# programs in
a controlled manner.
 A set of development tools, such as the csc compiler, which
turns C# programs into intermediate code (called Microsoft
Intermediate Language (MSIL)) that the CLR can understand.
 A set of standard libraries, like ADO.NET, which allow access to
databases (such as MS SQL Server or MySQL) and
WCF(Windows Communication Framework) which connects
applications through standard communication frameworks and
Protocols like HTTP, REST, JSON, SOAP and TCP sockets.
 .NET Core
 Is type of .NET standard which is free, open source,
general-purpose development platform to build cloud-
based software application on windows, Linux and
maCOS.
How C# code gets compiled and executed in .NET
Framework?:
 Step 1: write a C# code.
 Step 2: compile the code using a C# Compiler.
 Step 3: Now compiler check if the code contains error or not.
 In C# there are two types of errors:
 Compiler error: errors that occur when the developer
violates the rules of writing syntax.
Example: missing semicolon, missing parenthesis. Etc.
 Runtime error: errors that occur during program
execution(run-time) after successful compilation.
Exmple: division by zero
 Step 4: languages such as java or C# not directly
converted or compiled into machine level language or
machine instructions.
 These languages need to be converted to an intermediate
code first, which is a half compiled code.
 For C#, the source code is converted to an intermediate
code which is known as common intermediate(CIL) or
intermediate language code(ILC).
 This CIL or ILC code can run on any operating systems.
Because C# is a platform independent language.
 Step 5: after converting C# source code to common intermediate
language, the intermediate code needs to be converted to
machine understandable code.
 In C#, common language runtime is the basic and virtual machine
component of the .NET Framework.
 This virtual machine component translate the common language
intermediate language to machine understandable code.
 This process is called just in time compilations(JIT) or Dynamic
compilations which is the way of compiling code during the
execution of a program at run time only.
 Step 6: once the C# programs are compiled, they’re physically
packaged into Assemblies.
 An assembly is a file that contains one or more namespaces and
classes.
 As the number of class and namespace in program grows,
it is physically separated by related namespaces into
separate assemblies.
 Assemblies typically have the file extension .exe or .dll,
depending on whether we implement applications or
libraries respectively.
 Step 7: Now, the C# compiler returns the output of the
given C# code.
 IDE for C#
 A development tool, or integrated development environment (IDE), such as
Visual Studio isn’t essential for developing C# applications, but it makes things
much easier.
 Its possible to manipulate C# source code files in a basic text editor, such as
the ubiquitous Notepad application, and compile code into assemblies using
the command-line compiler that is part of the .NET Framework and .NET Core.
 Microsoft provides the following development tools for C# programming:
 Visual Studio
 Visual C# Express (VCE)
 Visual Web Develop

 Visual studio offers a great deal of versatility, providing users with an


expensive library of extensions that allows for more customization than other
environments.
A C# program consists of the following parts:
 Namespace - is a collection of related classes and
objects
and each has its own functionality.
 Class
 Class methods
 Class attributes
 A Main method
 Statements and Expressions
 Comments
 The Using Keyword is used to include the System
namespace in the program.
 Thenext line has the namespace declaration. A
namespace is a collection of classes.
 The next line has a class declaration, the class
Hello_World contains the data and method definitions that
your program uses.
 Classes generally contain multiple methods. Methods
define the behavior of the class. However, the Hello_World
class has only one Main method.
 Contains the Main method, which is the entry point for
all C# programs. The Main method states what the class
does when executed.
 Multiple line comments /*...*/ is ignored by the
compiler and it is put to add comments in the program.
 The Main method specifies its behavior with the
statement Console.WriteLine(”Hello World”);
C# basic input and output methods defined in Console Class:
 Console.WriteLine() is a method used to displays the output
and also provides a new line character it the end of the string,
This would set a new line for the next output.
 Console.Write() is a method that displays the output but do
not provide a new line character.
 Console.ReadLine() is a method used to read the next line of
characters from the standard input stream.
 Console.Read() is a method used to read the next character
from the standard input stream.
 Console.ReadKey() is a method that makes the program wait
for a key press and it prevents the screen until a key is
pressed.
 The C# controls are the building blocks on which
we can create the C# windows form programs.
 The toolbox is a palette of controls from which we
can select controls and place them in our forms.
 The intrinsic controls are built in controls in C#.
They can’t be replaced or removed from the
toolbox.
Some intrinsic controls in visual studio used for C# windows from
are:
 Label: Display tests in the form
 Panel: Serves as a container for other controls
 CheckBox: Enable users to select or deselect an options
 ComboBox: Allow users to select from a list of items or add a new value
 TextBox: Can be used to display text but also enables users to enter or
edit new or existing text.
 RichTextBox: Provides advanced text entry and editing feature such as
character and paragraph formatting.
 Timer: Lets your program perform actions in real time, without user
interaction
 PictureBox: Displays Graphics (Image) on a form but can’t be a
container.
 ListBox: Enables users to select form a list of items
For instance, Container is an object such as a form or the frame or
Picture-Box controls that can contain other controls.
 Based on this, fields are member variables of any type that is
declared directly in the class.
 Properties describes objects. Are members of a class that provides
a flexible mechanism to read, write or compute the value of a private
field.
 A Property is an attribute of an object that defines one of the objects
characteristics such as size, color, or screen location, or other
aspects of its behavior.
 Methods cause an object to do something. Is basic part of
program. It can solve a certain problem, eventually take
parameters and return a result. A Method represents all data
conversion a program does, to resolve a particular task.
 A Method is an action in which an object can perform. For
example, Add is a method of ComboBox object, because it
adds a new entry to a combo box.
 Events are what happens when an object does something.
Event can occur as the result of the user action or program
code, or the can be triggers by the system.
 An Event is an action recognized by an objects, such as clicking
the mouse or pressing a key, and for which you you can write
code to respond.
 Project is not the same as an application, it is the thing we use to create
the application.
 A project is a collection of source files that the C# compiler combines to
produce a single output—typically either an executable program or a
library.
 When you create an app or website in visual studio, you start with a
project.
 Project contains all files that are compiled into an executable, library, or
websites.
 Those files can include source code, icons, images, data files and so on.
 A project also contains a compiler setting and other configuration files
that might be needed by various services or components that your
program communicates with.
THANK YOU!!

You might also like