SlideShare a Scribd company logo
Object Oriented
Programming C#
Introducing the .NET Framework
and Visual Studio
• Goals of the .NET Framework
• Microsoft designed the .NET Framework with certain goals in mind. The
following sections examine these goals and how the .NET Framework
achieves them.
• Support of Industry Standards
• the framework relies heavily on industry standards such as the Extensible Markup
Language (XML), HTML 5, and OData.
• Extensibility
• Through inheritance and interfaces, you can easily access and extend the functionality of
these classes.
• Unified Programming Models
• you could develop a class written in C# that inherits from a class written using Visual
Basic (VB). Microsoft has developed several languages that support the .NET Framework.
Introducing the .NET Framework
and Visual Studio
• Goals of the .NET Framework
• Improved Memory Management
• Improved Security Model
Working with the .NET Framework
• Understanding Assemblies and Manifests
• The assembly contains the code, resources, and a manifest (metadata about the
assembly) needed to run the application. Assemblies can be organized into a single file
where all this information is incorporated into a single dynamic link library (DLL) file or
executable (EXE) file, or multiple files where the information is incorporated into
separate DLL files, graphics files, and a manifest file.
• Referencing Assemblies and Namespaces
• you create an instance of the System.Windows.Controls.TextBox class, like so:
private System.Windows.Controls.TextBox newTextBox;
Using the Visual Studio Integrated
Development Environment
• Creating a New project
• to create a new project, follow these
steps:
1. on the start page, click the Create
project link, which launches the new
project dialog box. (You can also choose
File ➤ new ➤ project to open this dialog
box.)
Introducing Objects and Classes
• In OOP, you use objects in your programs to encapsulate the data
associated with the entities with which the program is working. For
example, a human resources application needs to work with
employees. Employees have attributes associated with them that
need to be tracked.
• Defining Classes
Creating Class Methods
Using Constructors
• In OOP, you use constructors to
perform any processing that
needs to occur when an object
instance of the class becomes
instantiated. For example, you
could initialize properties of the
object instance or establish a
database connection.
Overloading Methods
• The ability to overload methods is a useful feature of OOP languages.
You overload methods in a class by defining multiple methods that
have the same name but contain different signatures.
Understanding Inheritance
• One of the most powerful
features of any OOP
language is inheritance.
Inheritance is the ability to
create a base class with
properties and methods
that can be used in classes
derived from the base
class.
Creating a Sealed Class
• By default, any C# class can be inherited. When creating classes that
can be inherited, you must take care that they are not modified in
such a way that derived classes no longer function as intended.
• Creating an Abstract Class
• At this point in the example, a client can access the GetBalance method through an instance
of the derived CheckingAccount class or directly through an instance of the base Account
class. Sometimes, you may want to have a base class that can’t be instantiated by client code.
Access to the methods and properties of the class must be through a derived class. In this
case, you construct the base class using the abstract modifier.
Using Access Modifiers in Base Classes
• When setting up class hierarchies using inheritance, you must manage how the
properties and methods of your classes are accessed. Two access modifiers you
have looked at so far are public and private. If a method or property of the base
class is exposed as public, it is accessible by both the derived class and any client
of the derived class. If you expose the property or method of the base class as
private, it is not accessible directly by the derived class or the client.
By defining the GetBalance method as protected, it becomes accessible to the derived class
CheckingAccount,
but not to the client code accessing an instance of the CheckingAccount class.
Overriding the Methods of a Base Class
• When a derived class inherits a method from a base class, it inherits
the implementation of that method. As the designer of the base class,
you may want to let a derived class implement the method in its own
unique way. This is known as overriding the base class method.
To override the Deposit method in the derived CheckingAccount class, use the following code:
Overriding the Methods of a Base Class
• One scenario to watch for is when a derived class inherits from the
base class and a second derived class inherits from the first derived
class. When a method overrides a method in the base class, it
becomes overridable by default. To limit an overriding method from
being overridden further up the inheritance chain, you must include
the sealed keyword in front of the override keyword in the method
definition of the derived class.
Calling a Base Class Method from a Derived
Class
• In some cases, you may want to develop a derived class method that
still uses the implementation code in the base class but also
augments it with its own implementation code. In this case, you
create an overriding method in the derived class and call the code in
the base class using the base qualifier.
Hiding Base Class Methods
• If a method in a derived class has the same
method signature as that of the base class
method, but it is not marked with the override
keyword, it effectively hides the method of
the base class. Although this may be the
intended behavior, sometimes it can occur
inadvertently. Although the code will still
compile, the IDE will issue a warning asking if
this is the intended behavior. If you intend to
hide a base class method, you should explicitly
use the new keyword in the definition of the
method of the derived class. Using the new
keyword will indicate to the IDE this is the
intended behavior and dismiss the warning.
Implementing Interfaces
• When you use an abstract class, classes that derive from it must implement its
inherited methods. You could use another technique to accomplish a similar
result. In this case, instead of defining an abstract class, you define an interface
that defines the method signatures.
• Classes that implement an interface are contractually required to implement the
interface signature definition and can’t alter it. This technique is useful to ensure
that client code using the classes knows which methods are available, how they
should be called, and the return values to expect.
Understanding Polymorphism
• For example, suppose you want all account classes in
a banking application to contain a GetAccountInfo
method with the same interface definition but
different implementations based on account type.
Client code could loop through a collection of
account-type classes, and the compiler would
determine at runtime which specific account-type
implementation needs to be executed. If you later
added a new account type that implements the
GetAccountInfo method, you would not need to
alter existing client code. You can achieve
polymorphism either by using inheritance or by
implementing interfaces. The following code
demonstrates the use of inheritance. First, you
define the base and derived classes.
Defining Method Signatures
• The following code demonstrates how methods are defined in C#. The
access modifier is first followed by the return type (void is used if no
return value is returned) and then the name of the method.
Parameter types and names are listed in parenthesis separated by
commas. The body of the method is contained in opening and closing
curly brackets.
Passing Parameters
• When you define a method in the class, you also must indicate how
the parameters are passed. Parameters may be passed by value or by
reference.
Understanding Delegation
• Delegation is when you request a service by making a method call to
a service provider. The service provider then reroutes this service
request to another method, which services the request.
Handling Exceptions in the .NET Framework
• Using the Try-Catch Block
Handling Exceptions in the .NET Framework
• Adding a Finally Block
Handling Exceptions in the .NET Framework
• Throwing Exceptions
Static Properties and Methods
• sometimes you may want different object instances of a class to
access the same, shared variables.
Using Asynchronous Messaging
• When a client object passes
a message asynchronously,
the client can continue
processing. After the server
completes the message
request, the response
information will be sent back
to the client.
Working with Collections
Working with Collections
Working with Arrays and Array Lists
• You access the elements of an array through its index.
The index is an integer representing the position of the
element in the array. For example, an array of strings
representing the days of the week has the following
index values:
• two-dimensional array where a student’s name (value) is
referenced by the ordered pair of row number, seat
number (index).
Working with Arrays and Array Lists
• The following code demonstrates declaring and working with an
array of integers. It also uses several static methods exposed by the
Array class. Notice the foreach loop used to list the values of the
array. The foreach loop provides a way to iterate through the
elements of the array.
Working with Arrays and Array Lists
• One comma indicates two dimensions; two commas indicate three
dimensions, and so forth. When filling a multidimensional array,
curly brackets within curly brackets define the elements. The
following code declares and fills a two-dimensional array:
Working with Arrays and Array Lists
• When you work with collections, you often do not know the
number of items they need to contain until runtime. This is where
the ArrayList class fits in. The capacity of an array list automatically
expands as required, with the memory reallocation and copying of
elements performed automatically.
Programming with Stacks and Queues
Implementing the Data Access Layer
• Introducing ADO.NET
• To access and work with data in a consistent way across these various data stores, the .NET
Framework provides a set of classes organized into the System.Data namespace. This
collection of classes is known as ADO.NET.
• Establishing a Connection
Executing a Command
A Command object stores and executes command statements against the database. You can use the Command object to execute
any valid SQL statement understood by the data store. In the case of SQL Server, these can be Data Manipulation Language
statements (Select, Insert, Update, and Delete), Data Definition Language statements (Create, Alter, and Drop), or Data Control
Language statements (Grant, Deny, and Revoke)
Using Stored Procedures
Using Stored Procedures
When executing a stored procedure,
you often must supply input
parameters. You may also need to
retrieve the results of the stored
procedure through output
parameters. To work with
parameters, you need to instantiate
a parameter object of type
SqlParameter, and then add it to the
Parameters collection of the
Command object.
Using the DataReader Object to Retrieve Data
Using the DataAdapter to Retrieve Data
Populating a DataTable from a SQL Server
Database
• The Load method of the
DataTable fills the table
with the contents of a
DataReader object.
Populating a DataSet from a SQL Server
Database
• Create a separate DataAdapter for each
DataTable. The final step is to fill the
DataSet with the data by executing the Fill
method of the DataAdapter. The following
code demonstrates filling a DataSet with
data from the publishers table and the
titles table of the Pubs database
Developing WPF Applications
Introducing XAML
Adding Display Controls
Working with windows and controls
Creating and Using Dialog Boxes
Creating a Custom Dialog Box
LoginDialog
Data Binding in Windows-Based GUIs
• To bind a control to data, you need a data source object. The DataContext of a container control
allows child controls to inherit information from their parent controls about the data source that
is used for binding. The following code sets the DataContext property of the top level Window
control.
Creating and Using Control and Data
Templates
• In WPF, every control has a template that manages its visual appearance. If you don’t explicitly set
its Style property, then it uses a default template. Creating a custom template and assigning it to
the Style property is an excellent way to alter the look and feel of your applications.
ListBox using the default DataTemplate
ListBox using the default DataTemplate
Developing Web Applications
Code contained in the .aspx file
Web page rendered in IE
Web Server Control Fundamentals
• The .NET Framework provides a set of Web server controls specifically for hosting within a Web
Form. The types of Web server controls available include common form controls such as a
TextBox, Label, and Button, as well as more complex controls such as a GridView and a Calendar.
The Web server controls abstract out the HTML coding from the developer. When the Page class
sends the response stream to the browser, the Web server control is rendered on the page using
the appropriate HTML.
Using the Visual Studio Web Page Designer
The Visual Studio Integrated Development Environment (IDE) includes an excellent Web Page Designer. Using
the designer, you can drag and drop controls onto the Web Page from the Toolbox and set control properties
using the Properties window.
The Web Page Life Cycle
Control Events
• When an event occurs on the client—for example, a button click—the event information is
captured on the client and the information is transmitted to the server via a Hypertext Transfer
Protocol (HTTP) post. On the server, the event information is intercepted by an event delegate
object, which in turn informs any event handler methods that have subscribed to the invocation
list.
Understanding Application and Session Events
• Along with the Page and control events, the .NET
Framework provides the ability to intercept and
respond to events raised when a Web session starts
or ends. A Web session starts when a user requests
a page from the application and ends when the
session is abandoned or it times out. In addition to
the session events, the .NET Framework exposes
several application-level events. The
Application_Start event occurs the first time
anyone requests a page in the Web application.
Application_BeginRequest occurs when any page or
service is requested. There are corresponding
events that fire when ending requests,
authenticating users, raising errors, and stopping
the application. The session-level and application-
level event handlers are in the Global.asax.cs code-
behind file.
Using Query Strings
• While view state is used to store information between post backs to the same page, you often
need to pass information from one page to another. One popular way to accomplish this is
through the use of query strings. A query string is appended to the page request URL
Using Cookies
• You can use cookies to store small amounts of data in a text file located on the client device. The
HttpResponse class’s Cookie property provides access to the Cookies collection. The Cookies collection
contains cookies transmitted by the client to the server in the Cookies header. This collection contains
cookies originally generated on the server and transmitted to the client in the Set-Cookie header. Because
the browser can only send cookie data to the server that originally created the cookie, and cookie
information can be encrypted before being sent to the browser, it is a fairly secure way of maintaining user
data. A common use for cookies is to send a user identity token to the client that can be retrieved the next
time the user visits the site.
To read a cookie, you use the Request object.
Maintaining Session and Application State
• Session state is the ability to maintain information pertinent to a user as they request the various pages
within a Web application. Session state is maintained on the server and is provided by an object instance of
the HttpSessionState class.
• Although session state is scoped on a per-session basis, there are times a Web application needs to share a
state among all sessions in the application. You can achieve this globally scoped state using an object
instance of the HttpApplicationState class. The application state is stored in a key-value dictionary structure
similar to the session state, except that it is available to all sessions and from all forms in the application.
Data-Bound Web Controls
• Data-bound controls automate the process of presenting data in a web form. ASP.NET provides
various controls to display the data depending on the type of data, how it should be displayed,
and whether it can be updated. Some of these controls are used to present read-only data, for
example, the Repeater control displays a list of read-only data. If you need to update the data in a
list, you could use the ListView control. If you need to display many columns and rows of data in a
tabular format, you would use the GridView control. If you need to display a single record at a
time, you could use the DetailsView or the FormView controls.
Data-Bound Web Controls
Model Binding
• To configure a data control to use
model binding to select data, you
set the control’s SelectMethod
property to the name of a method
in the page’s code. In the case
above, the SelectMethod is set to
the GetEmployee method which
returns a list of Employee objects.
The data control calls the method
at the appropriate time in the
page life cycle and automatically
binds the returned data.
Thank You
• Prepared by:
• Muhammad Alaa
• eng.Muhammad.younis@gmail.com
Ad

More Related Content

What's hot (20)

2. overview of c#
2. overview of c#2. overview of c#
2. overview of c#
Rohit Rao
 
OOPs with Java - Packaging and Access Modifiers
OOPs with Java - Packaging and Access Modifiers OOPs with Java - Packaging and Access Modifiers
OOPs with Java - Packaging and Access Modifiers
Hitesh-Java
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
Object oriented programming-with_java
Object oriented programming-with_javaObject oriented programming-with_java
Object oriented programming-with_java
Hoang Nguyen
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Sagar Verma
 
70 536
70 53670 536
70 536
Sankar Balasubramanian
 
Class notes(week 7) on packages
Class notes(week 7) on packagesClass notes(week 7) on packages
Class notes(week 7) on packages
Kuntal Bhowmick
 
Oops in Java
Oops in JavaOops in Java
Oops in Java
malathip12
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
bindur87
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Andres Baravalle
 
Java packages
Java packagesJava packages
Java packages
Jeffrey Quevedo
 
OOP with Java - Continued
OOP with Java - Continued OOP with Java - Continued
OOP with Java - Continued
Hitesh-Java
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
Krishnaov
 
Inner Classes
Inner Classes Inner Classes
Inner Classes
Hitesh-Java
 
Packages and Interfaces
Packages and InterfacesPackages and Interfaces
Packages and Interfaces
AkashDas112
 
Basics of Java
Basics of JavaBasics of Java
Basics of Java
Sherihan Anver
 
Java Object Oriented Programming
Java Object Oriented Programming Java Object Oriented Programming
Java Object Oriented Programming
University of Potsdam
 
Java core - Detailed Overview
Java  core - Detailed OverviewJava  core - Detailed Overview
Java core - Detailed Overview
Buddha Tree
 
OOP in Java
OOP in JavaOOP in Java
OOP in Java
wiradikusuma
 
Unit 4
Unit 4Unit 4
Unit 4
LOVELY PROFESSIONAL UNIVERSITY
 
2. overview of c#
2. overview of c#2. overview of c#
2. overview of c#
Rohit Rao
 
OOPs with Java - Packaging and Access Modifiers
OOPs with Java - Packaging and Access Modifiers OOPs with Java - Packaging and Access Modifiers
OOPs with Java - Packaging and Access Modifiers
Hitesh-Java
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
Object oriented programming-with_java
Object oriented programming-with_javaObject oriented programming-with_java
Object oriented programming-with_java
Hoang Nguyen
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Sagar Verma
 
Class notes(week 7) on packages
Class notes(week 7) on packagesClass notes(week 7) on packages
Class notes(week 7) on packages
Kuntal Bhowmick
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
bindur87
 
OOP with Java - Continued
OOP with Java - Continued OOP with Java - Continued
OOP with Java - Continued
Hitesh-Java
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
Krishnaov
 
Packages and Interfaces
Packages and InterfacesPackages and Interfaces
Packages and Interfaces
AkashDas112
 
Java core - Detailed Overview
Java  core - Detailed OverviewJava  core - Detailed Overview
Java core - Detailed Overview
Buddha Tree
 

Similar to Object Oriented Programming C# (20)

Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
agorolabs
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
Hari kiran G
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
KunalYadav65140
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
RaazIndia
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
Java
JavaJava
Java
nirbhayverma8
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
Ajay Chimmani
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
Connex
 
Java_notes.ppt
Java_notes.pptJava_notes.ppt
Java_notes.ppt
tuyambazejeanclaude
 
Lec 1.9 oop
Lec 1.9 oopLec 1.9 oop
Lec 1.9 oop
Badar Waseer
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
AnmolVerma363503
 
Object-oriented programming 3.pptx
Object-oriented programming 3.pptxObject-oriented programming 3.pptx
Object-oriented programming 3.pptx
Adikhan27
 
Unit II Inheritance ,Interface and Packages.pptx
Unit II   Inheritance ,Interface and Packages.pptxUnit II   Inheritance ,Interface and Packages.pptx
Unit II Inheritance ,Interface and Packages.pptx
pranalisonawane8600
 
Apex code (Salesforce)
Apex code (Salesforce)Apex code (Salesforce)
Apex code (Salesforce)
Mohammed Safwat Abu Kwaik
 
Share Unit 1- Basic concept of object-oriented-programming.ppt
Share Unit 1- Basic concept of object-oriented-programming.pptShare Unit 1- Basic concept of object-oriented-programming.ppt
Share Unit 1- Basic concept of object-oriented-programming.ppt
hannahrroselin95
 
Object Oriented Programming (Advanced )
Object Oriented Programming   (Advanced )Object Oriented Programming   (Advanced )
Object Oriented Programming (Advanced )
ayesha420248
 
Abstraction encapsulation inheritance polymorphism
Abstraction encapsulation inheritance polymorphismAbstraction encapsulation inheritance polymorphism
Abstraction encapsulation inheritance polymorphism
PriyadharshiniG41
 
Java scjp-part1
Java scjp-part1Java scjp-part1
Java scjp-part1
Raghavendra V Gayakwad
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
Ahmed Farag
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
Questpond
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
agorolabs
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
Hari kiran G
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
KunalYadav65140
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
RaazIndia
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
Ajay Chimmani
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
Connex
 
Object-oriented programming 3.pptx
Object-oriented programming 3.pptxObject-oriented programming 3.pptx
Object-oriented programming 3.pptx
Adikhan27
 
Unit II Inheritance ,Interface and Packages.pptx
Unit II   Inheritance ,Interface and Packages.pptxUnit II   Inheritance ,Interface and Packages.pptx
Unit II Inheritance ,Interface and Packages.pptx
pranalisonawane8600
 
Share Unit 1- Basic concept of object-oriented-programming.ppt
Share Unit 1- Basic concept of object-oriented-programming.pptShare Unit 1- Basic concept of object-oriented-programming.ppt
Share Unit 1- Basic concept of object-oriented-programming.ppt
hannahrroselin95
 
Object Oriented Programming (Advanced )
Object Oriented Programming   (Advanced )Object Oriented Programming   (Advanced )
Object Oriented Programming (Advanced )
ayesha420248
 
Abstraction encapsulation inheritance polymorphism
Abstraction encapsulation inheritance polymorphismAbstraction encapsulation inheritance polymorphism
Abstraction encapsulation inheritance polymorphism
PriyadharshiniG41
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
Ahmed Farag
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
Questpond
 
Ad

More from Muhammad Younis (11)

Linq to sql
Linq to sqlLinq to sql
Linq to sql
Muhammad Younis
 
Google maps api 3
Google maps api 3Google maps api 3
Google maps api 3
Muhammad Younis
 
Microsoft reports
Microsoft reportsMicrosoft reports
Microsoft reports
Muhammad Younis
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
Muhammad Younis
 
Mvc4
Mvc4Mvc4
Mvc4
Muhammad Younis
 
Mvc webforms
Mvc webformsMvc webforms
Mvc webforms
Muhammad Younis
 
Share point overview
Share point overviewShare point overview
Share point overview
Muhammad Younis
 
Lightswitch
LightswitchLightswitch
Lightswitch
Muhammad Younis
 
Mvc summary
Mvc summaryMvc summary
Mvc summary
Muhammad Younis
 
Mvc3 part2
Mvc3   part2Mvc3   part2
Mvc3 part2
Muhammad Younis
 
Mvc3 part1
Mvc3   part1Mvc3   part1
Mvc3 part1
Muhammad Younis
 
Ad

Recently uploaded (20)

Unit 4: Long term- Capital budgeting and its types
Unit 4: Long term- Capital budgeting and its typesUnit 4: Long term- Capital budgeting and its types
Unit 4: Long term- Capital budgeting and its types
bharath321164
 
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd yearVitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
ARUN KUMAR
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Studying Drama: Definition, types and elements
Studying Drama: Definition, types and elementsStudying Drama: Definition, types and elements
Studying Drama: Definition, types and elements
AbdelFattahAdel2
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-26-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-26-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-26-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-26-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Unit 4: Long term- Capital budgeting and its types
Unit 4: Long term- Capital budgeting and its typesUnit 4: Long term- Capital budgeting and its types
Unit 4: Long term- Capital budgeting and its types
bharath321164
 
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd yearVitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
ARUN KUMAR
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Studying Drama: Definition, types and elements
Studying Drama: Definition, types and elementsStudying Drama: Definition, types and elements
Studying Drama: Definition, types and elements
AbdelFattahAdel2
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 

Object Oriented Programming C#

  • 2. Introducing the .NET Framework and Visual Studio • Goals of the .NET Framework • Microsoft designed the .NET Framework with certain goals in mind. The following sections examine these goals and how the .NET Framework achieves them. • Support of Industry Standards • the framework relies heavily on industry standards such as the Extensible Markup Language (XML), HTML 5, and OData. • Extensibility • Through inheritance and interfaces, you can easily access and extend the functionality of these classes. • Unified Programming Models • you could develop a class written in C# that inherits from a class written using Visual Basic (VB). Microsoft has developed several languages that support the .NET Framework.
  • 3. Introducing the .NET Framework and Visual Studio • Goals of the .NET Framework • Improved Memory Management • Improved Security Model
  • 4. Working with the .NET Framework • Understanding Assemblies and Manifests • The assembly contains the code, resources, and a manifest (metadata about the assembly) needed to run the application. Assemblies can be organized into a single file where all this information is incorporated into a single dynamic link library (DLL) file or executable (EXE) file, or multiple files where the information is incorporated into separate DLL files, graphics files, and a manifest file. • Referencing Assemblies and Namespaces • you create an instance of the System.Windows.Controls.TextBox class, like so: private System.Windows.Controls.TextBox newTextBox;
  • 5. Using the Visual Studio Integrated Development Environment • Creating a New project • to create a new project, follow these steps: 1. on the start page, click the Create project link, which launches the new project dialog box. (You can also choose File ➤ new ➤ project to open this dialog box.)
  • 6. Introducing Objects and Classes • In OOP, you use objects in your programs to encapsulate the data associated with the entities with which the program is working. For example, a human resources application needs to work with employees. Employees have attributes associated with them that need to be tracked. • Defining Classes
  • 8. Using Constructors • In OOP, you use constructors to perform any processing that needs to occur when an object instance of the class becomes instantiated. For example, you could initialize properties of the object instance or establish a database connection.
  • 9. Overloading Methods • The ability to overload methods is a useful feature of OOP languages. You overload methods in a class by defining multiple methods that have the same name but contain different signatures.
  • 10. Understanding Inheritance • One of the most powerful features of any OOP language is inheritance. Inheritance is the ability to create a base class with properties and methods that can be used in classes derived from the base class.
  • 11. Creating a Sealed Class • By default, any C# class can be inherited. When creating classes that can be inherited, you must take care that they are not modified in such a way that derived classes no longer function as intended. • Creating an Abstract Class • At this point in the example, a client can access the GetBalance method through an instance of the derived CheckingAccount class or directly through an instance of the base Account class. Sometimes, you may want to have a base class that can’t be instantiated by client code. Access to the methods and properties of the class must be through a derived class. In this case, you construct the base class using the abstract modifier.
  • 12. Using Access Modifiers in Base Classes • When setting up class hierarchies using inheritance, you must manage how the properties and methods of your classes are accessed. Two access modifiers you have looked at so far are public and private. If a method or property of the base class is exposed as public, it is accessible by both the derived class and any client of the derived class. If you expose the property or method of the base class as private, it is not accessible directly by the derived class or the client. By defining the GetBalance method as protected, it becomes accessible to the derived class CheckingAccount, but not to the client code accessing an instance of the CheckingAccount class.
  • 13. Overriding the Methods of a Base Class • When a derived class inherits a method from a base class, it inherits the implementation of that method. As the designer of the base class, you may want to let a derived class implement the method in its own unique way. This is known as overriding the base class method. To override the Deposit method in the derived CheckingAccount class, use the following code:
  • 14. Overriding the Methods of a Base Class • One scenario to watch for is when a derived class inherits from the base class and a second derived class inherits from the first derived class. When a method overrides a method in the base class, it becomes overridable by default. To limit an overriding method from being overridden further up the inheritance chain, you must include the sealed keyword in front of the override keyword in the method definition of the derived class.
  • 15. Calling a Base Class Method from a Derived Class • In some cases, you may want to develop a derived class method that still uses the implementation code in the base class but also augments it with its own implementation code. In this case, you create an overriding method in the derived class and call the code in the base class using the base qualifier.
  • 16. Hiding Base Class Methods • If a method in a derived class has the same method signature as that of the base class method, but it is not marked with the override keyword, it effectively hides the method of the base class. Although this may be the intended behavior, sometimes it can occur inadvertently. Although the code will still compile, the IDE will issue a warning asking if this is the intended behavior. If you intend to hide a base class method, you should explicitly use the new keyword in the definition of the method of the derived class. Using the new keyword will indicate to the IDE this is the intended behavior and dismiss the warning.
  • 17. Implementing Interfaces • When you use an abstract class, classes that derive from it must implement its inherited methods. You could use another technique to accomplish a similar result. In this case, instead of defining an abstract class, you define an interface that defines the method signatures. • Classes that implement an interface are contractually required to implement the interface signature definition and can’t alter it. This technique is useful to ensure that client code using the classes knows which methods are available, how they should be called, and the return values to expect.
  • 18. Understanding Polymorphism • For example, suppose you want all account classes in a banking application to contain a GetAccountInfo method with the same interface definition but different implementations based on account type. Client code could loop through a collection of account-type classes, and the compiler would determine at runtime which specific account-type implementation needs to be executed. If you later added a new account type that implements the GetAccountInfo method, you would not need to alter existing client code. You can achieve polymorphism either by using inheritance or by implementing interfaces. The following code demonstrates the use of inheritance. First, you define the base and derived classes.
  • 19. Defining Method Signatures • The following code demonstrates how methods are defined in C#. The access modifier is first followed by the return type (void is used if no return value is returned) and then the name of the method. Parameter types and names are listed in parenthesis separated by commas. The body of the method is contained in opening and closing curly brackets.
  • 20. Passing Parameters • When you define a method in the class, you also must indicate how the parameters are passed. Parameters may be passed by value or by reference.
  • 21. Understanding Delegation • Delegation is when you request a service by making a method call to a service provider. The service provider then reroutes this service request to another method, which services the request.
  • 22. Handling Exceptions in the .NET Framework • Using the Try-Catch Block
  • 23. Handling Exceptions in the .NET Framework • Adding a Finally Block
  • 24. Handling Exceptions in the .NET Framework • Throwing Exceptions
  • 25. Static Properties and Methods • sometimes you may want different object instances of a class to access the same, shared variables.
  • 26. Using Asynchronous Messaging • When a client object passes a message asynchronously, the client can continue processing. After the server completes the message request, the response information will be sent back to the client.
  • 29. Working with Arrays and Array Lists • You access the elements of an array through its index. The index is an integer representing the position of the element in the array. For example, an array of strings representing the days of the week has the following index values: • two-dimensional array where a student’s name (value) is referenced by the ordered pair of row number, seat number (index).
  • 30. Working with Arrays and Array Lists • The following code demonstrates declaring and working with an array of integers. It also uses several static methods exposed by the Array class. Notice the foreach loop used to list the values of the array. The foreach loop provides a way to iterate through the elements of the array.
  • 31. Working with Arrays and Array Lists • One comma indicates two dimensions; two commas indicate three dimensions, and so forth. When filling a multidimensional array, curly brackets within curly brackets define the elements. The following code declares and fills a two-dimensional array:
  • 32. Working with Arrays and Array Lists • When you work with collections, you often do not know the number of items they need to contain until runtime. This is where the ArrayList class fits in. The capacity of an array list automatically expands as required, with the memory reallocation and copying of elements performed automatically.
  • 34. Implementing the Data Access Layer • Introducing ADO.NET • To access and work with data in a consistent way across these various data stores, the .NET Framework provides a set of classes organized into the System.Data namespace. This collection of classes is known as ADO.NET. • Establishing a Connection
  • 35. Executing a Command A Command object stores and executes command statements against the database. You can use the Command object to execute any valid SQL statement understood by the data store. In the case of SQL Server, these can be Data Manipulation Language statements (Select, Insert, Update, and Delete), Data Definition Language statements (Create, Alter, and Drop), or Data Control Language statements (Grant, Deny, and Revoke)
  • 37. Using Stored Procedures When executing a stored procedure, you often must supply input parameters. You may also need to retrieve the results of the stored procedure through output parameters. To work with parameters, you need to instantiate a parameter object of type SqlParameter, and then add it to the Parameters collection of the Command object.
  • 38. Using the DataReader Object to Retrieve Data
  • 39. Using the DataAdapter to Retrieve Data
  • 40. Populating a DataTable from a SQL Server Database • The Load method of the DataTable fills the table with the contents of a DataReader object.
  • 41. Populating a DataSet from a SQL Server Database • Create a separate DataAdapter for each DataTable. The final step is to fill the DataSet with the data by executing the Fill method of the DataAdapter. The following code demonstrates filling a DataSet with data from the publishers table and the titles table of the Pubs database
  • 44. Working with windows and controls
  • 45. Creating and Using Dialog Boxes
  • 46. Creating a Custom Dialog Box LoginDialog
  • 47. Data Binding in Windows-Based GUIs • To bind a control to data, you need a data source object. The DataContext of a container control allows child controls to inherit information from their parent controls about the data source that is used for binding. The following code sets the DataContext property of the top level Window control.
  • 48. Creating and Using Control and Data Templates • In WPF, every control has a template that manages its visual appearance. If you don’t explicitly set its Style property, then it uses a default template. Creating a custom template and assigning it to the Style property is an excellent way to alter the look and feel of your applications.
  • 49. ListBox using the default DataTemplate
  • 50. ListBox using the default DataTemplate
  • 51. Developing Web Applications Code contained in the .aspx file Web page rendered in IE
  • 52. Web Server Control Fundamentals • The .NET Framework provides a set of Web server controls specifically for hosting within a Web Form. The types of Web server controls available include common form controls such as a TextBox, Label, and Button, as well as more complex controls such as a GridView and a Calendar. The Web server controls abstract out the HTML coding from the developer. When the Page class sends the response stream to the browser, the Web server control is rendered on the page using the appropriate HTML.
  • 53. Using the Visual Studio Web Page Designer The Visual Studio Integrated Development Environment (IDE) includes an excellent Web Page Designer. Using the designer, you can drag and drop controls onto the Web Page from the Toolbox and set control properties using the Properties window.
  • 54. The Web Page Life Cycle
  • 55. Control Events • When an event occurs on the client—for example, a button click—the event information is captured on the client and the information is transmitted to the server via a Hypertext Transfer Protocol (HTTP) post. On the server, the event information is intercepted by an event delegate object, which in turn informs any event handler methods that have subscribed to the invocation list.
  • 56. Understanding Application and Session Events • Along with the Page and control events, the .NET Framework provides the ability to intercept and respond to events raised when a Web session starts or ends. A Web session starts when a user requests a page from the application and ends when the session is abandoned or it times out. In addition to the session events, the .NET Framework exposes several application-level events. The Application_Start event occurs the first time anyone requests a page in the Web application. Application_BeginRequest occurs when any page or service is requested. There are corresponding events that fire when ending requests, authenticating users, raising errors, and stopping the application. The session-level and application- level event handlers are in the Global.asax.cs code- behind file.
  • 57. Using Query Strings • While view state is used to store information between post backs to the same page, you often need to pass information from one page to another. One popular way to accomplish this is through the use of query strings. A query string is appended to the page request URL
  • 58. Using Cookies • You can use cookies to store small amounts of data in a text file located on the client device. The HttpResponse class’s Cookie property provides access to the Cookies collection. The Cookies collection contains cookies transmitted by the client to the server in the Cookies header. This collection contains cookies originally generated on the server and transmitted to the client in the Set-Cookie header. Because the browser can only send cookie data to the server that originally created the cookie, and cookie information can be encrypted before being sent to the browser, it is a fairly secure way of maintaining user data. A common use for cookies is to send a user identity token to the client that can be retrieved the next time the user visits the site. To read a cookie, you use the Request object.
  • 59. Maintaining Session and Application State • Session state is the ability to maintain information pertinent to a user as they request the various pages within a Web application. Session state is maintained on the server and is provided by an object instance of the HttpSessionState class. • Although session state is scoped on a per-session basis, there are times a Web application needs to share a state among all sessions in the application. You can achieve this globally scoped state using an object instance of the HttpApplicationState class. The application state is stored in a key-value dictionary structure similar to the session state, except that it is available to all sessions and from all forms in the application.
  • 60. Data-Bound Web Controls • Data-bound controls automate the process of presenting data in a web form. ASP.NET provides various controls to display the data depending on the type of data, how it should be displayed, and whether it can be updated. Some of these controls are used to present read-only data, for example, the Repeater control displays a list of read-only data. If you need to update the data in a list, you could use the ListView control. If you need to display many columns and rows of data in a tabular format, you would use the GridView control. If you need to display a single record at a time, you could use the DetailsView or the FormView controls.
  • 62. Model Binding • To configure a data control to use model binding to select data, you set the control’s SelectMethod property to the name of a method in the page’s code. In the case above, the SelectMethod is set to the GetEmployee method which returns a list of Employee objects. The data control calls the method at the appropriate time in the page life cycle and automatically binds the returned data.
  • 63. Thank You • Prepared by: • Muhammad Alaa • [email protected]