1 / 181

Index

C#. Introduction to OOPS Oops Concept Introduction to C# Dot Net Framework Literals and Data Types Branching and Looping Constructor Inheritance Abstract Class Interface Delegates Events Structure Arrays Enumerator Collections Exception Handling Sealed Class Files Generics.

pahana
Télécharger la présentation

Index

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C#

  2. Introduction to OOPS Oops Concept Introduction to C# Dot Net Framework Literals and Data Types Branching and Looping Constructor Inheritance Abstract Class Interface Delegates Events Structure Arrays Enumerator Collections Exception Handling Sealed Class Files Generics Index

  3. Oooops…!

  4. Contents: • Introduction • Classes And Object • OOPS Concepts • Advantages

  5. INTRODUCTION • Object-Oriented Programming allows programmers to use the same terminology to explain the business domain and the program. • OOPenables users to model real-world objects. Modeling means representing real-world objects as components.

  6. Explanation • Before OOP, programmers used to creating computer applications using procedural-programming (or structure-programming) • In procedural- programming all the program functionality written in a few modules of code or maybe one module (depending on the program). • These modules depend on one another and maybe if you change a line of code you will have to rewrite the whole module again and maybe the whole program. • The introduction of OOP, solved lots of problems of procedural programming. • In oops codes are written in independent parts called ‘classes’. Each program functionality is divided into classes. The assembly combines these classes to form a single program. • Now if any changes has to be made then that particular or specific class is taken and necessary changes is to be made.

  7. The single entity holding the data and methods is called a “class”. An “Object” is an instance of a class.Eg: Car is a class and engine is an object. People is a class and Mary is an object. A class is a plan from which many objects can be created. CLASS & OBJECT

  8. Suppose that someone builds a paper pattern for a shirt. All the shirts done with the same paper pattern will be identical (same design, size, etc.). In this sample, the paper pattern is the class and the shirt is the object. To build the same exact shirt over and over, you need the paper pattern as a template. Paper Pattern is the Class And Shirt is the Object

  9. OOPS CONCEPTS • Polymorphism • Encapsulation • Abstraction • Inheritance

  10. INHERITANCE • Inheritance creates a hierarchy of classes and helps you reuse the code of a parent class in a child class. • A Class inherits the attributes and behavior of its parent class or superclass. • Superclass: Base class: Parent class. Subclass: Derived class: Child class. • The mechanism of constructing one class from an other class is called “Inheritance”.

  11. Syntax:<<Access modifiers>> class <subclass name> extends <superclass name> • The Shape class is the parent class. Square, Rectangle, and Circle are derived classes that inherit from Shape. • class declaration class child: parent  • class Square: Shape Shape Rectangle Circle Triangle

  12. ENCAPSULATION • Encapsulation hides internal implementation details from users. • Internal details, such as data representation should not be accessible externally, this protects outside users from making internal changes. • There is visibility to the functionalities offered by an object, and no visibility to its data. • Encapsulation means hiding of non-essential details.

  13. EXAMPLE • When a user selects a command from a menu in an application, the code used to perform the actions of that command is hidden from the user. • A Customer may issue a check and now know how it is processed. The internal processing is hidden from the customer.

  14. ABSTRACTION • Abstraction means representing of essential details. • An abstract class is a parent class that allows inheritance but can never be instantiated. • Abstract classes contain one or more abstract methods that do not have implementation.

  15. Shape • A Shape class, which is an abstract class. In the real world, you never calculate the area or perimeter of a generic shape, you must know what kind of geometric shape you have because each shape (eg. square, circle, rectangle, etc.) has its own area and perimeter formulas. • People own savings accounts, checking accounts, credit accounts, investment accounts, but not generic bank accounts. In this case, a bank account can be an abstract class and all the other specialized bank accounts inherit from bank account. Circle Rectangle Triangle

  16. POLYMORPHISM • Polymorphism means one entity existing in multiple forms. • The design principle used in this is the same message sent to different objects results in different behavior. • Even though classes are derived or inherited from the same parent class, each derived class will have its own behavior.

  17. EXAMPLE Shape • All of them are shapes and as shapes their area and perimeter can be calculated; however, each shape calculates its area in a specialized way. • In the same way Every key of a keyboard performs a specific action when a keystroke message is generated for that key. However, by using polymorphism, the same code with a small change can be used by different keys of the keyboard to trigger specific actions. Circle Area=3.14*r*r (r=Radius) Rectangle Area=H*W (H=height, W=width) Square Area=4*S*S (S=side)

  18. Advantages • Enables the use of real-world modeling . - Any real world object is considered as an object. • Promotes the reuse of code. -By the use of inheritance etc, coding in a single class can beused many times. • Provides flexibility in the modification of an existing application . -If any changes in a single line code, only that specific class is taken and made necessary changes. • Helps with the maintainability of code. -You can create classes for different types of organization. - This helps in maintaining data information separately.

  19. INTRODUCTION TO C SHARP

  20. Contents: • Introduction • What Lead to C# • Features in C# • Characteristics in C#

  21. C# • C# (pronounced "C sharp") is a programming language that is designed for building a variety of applications that run on the .NET Framework. • C# is simple, powerful, type-safe, and object-oriented. • Delegates, Interface, Foreach Statements, Enumerations are few features in C# which lag in C++. • The first component oriented language in the C/C++ family

  22. What lead C# C/C++ Drawbacks: • Poor type safety. • High complexity of language. • Memory leakage. • Weak in consistency. Visual Basic Drawbacks: • Truly not Object- Oriented. • Also could not meet the requirements of World Wide Web. Java Drawbacks: • Lacking in inter-operability with code of other languages. • Truly Object-Oriented but does not feature like Operating Overloading. • Hence keeping in view of these drawbacks, The Microsoft wanted new language that will suite the requirements of WorldWide Web Application. Hence, Lead to the Introduction of c#( pronounced "C sharp").

  23. New Features: Boxing/UnBoxing. For each Statements. Go to. Events Delegates Interfaces Rectangular Arrays Productivity of Visual Basic, Power of C++and Elegance of Javacombines to form C#.C# is the combination of 70% of Java,10% of C++,5% of Visual Basic and 15% newfeatures.

  24. Indexes • Exception Handling • Data Types Characteristics of c#: • Object Oriented • Garbage Collection • Namespace • Data Types • Inter Operability • Versionable • Security

  25. .NET FrameWork

  26. Contents: • Introduction • DotNet Architecture • Common Language Runtime • Base Class Library • DotNet Framework Services • DotNet Execution Model • C# and DotNet

  27. Dot Net Framework • C# is mainly dependent for supporting the key features of dot net framework. • The dot net framework provides an environment for building, deploying and running web services and other applications. • This is the working platform for applications.

  28. Dot Net Framework Architecture VB C++ C# JAVA …. Visual Studio Dot NET Common Language Specification ASP. NET Web forms, Web Services Window Forms ADO.NET and XML Base Class Library Common Language Runtime

  29. Common Language Runtime • Common Language Runtime: -it’s a runtime engine which manages the runtime code (c# application). -is a part of dot net framework. • Simplify Application Development, Deployment and Management. • Managed code: -a code that satisfies the CLR.

  30. Common Language Runtime Program written in any DOT NET language (C#,VB.Net etc) Compiler Intermediate Language (IL) (.exe or .dll) Compiler Common Language Runtime Loads and Executes code

  31. Common Type System: -Defines rules that languages must follow, which helps ensure that objects written in different languages can interact with each other. -is responsible for interpreting the data types into the common format - e.g. how many bytes is an integer. • Common Language Specification: -This ensure inter-operability between Languages. -All the rules that apply to the common type system apply to the CLS, except where stricter rules are defined in the CLS.

  32. IL Compiler: -takes in the IL code and converts it to the host machine language. • Security: -ensures that the assembly (the program being executed) has permissions to execute certain functions. • Garbage collector: -Its function is to reclaim the memory when the object is no longer in use, this avoids memory leaks and dangling pointers. • Class loader: -Its sole purpose is to load the classes needed by the executing application.

  33. .Net Framework Services • ASP.NET: -It’s a server side scripting technology. • Web Forms: -Manageable code • Window Forms: -Framework for building rich controls. • ADO.Net: -Used as connectivity( e.g.: datasets) -XML support.

  34. .NET Base Class Libraries System.Web System.WinForms Design ComponentModel Services UI Description HtmlControls Discovery WebControls Protocols System.Drawing Drawing2D Printing Caching Security Imaging Text Configuration SessionState System.Data System.Xml ADO SQL XSLT Serialization Design SQLTypes XPath System Collections IO Security Runtime InteropServices Configuration Net ServiceProcess Remoting Diagnostics Reflection Text Serialization Globalization Resources Threading

  35. Base Class Library • The Framework Class Library or FCL nothing short of a massive collection of classes, structures, enumerated types and interfaces defined and implemented for reuse in your managed software. • If you like, you can use it like any other library. • That is to say that you can write applications that make use of the objects in the Base Class Library to read files, display windows, and do various tasks. • The FCL is a class library; however it has been designed for extendibility and compose ability. This is advanced reuse.

  36. Planning Analysis Design Manage and Collaborate Development Testing Deployment .NET Platform Visual Studio .NET • Visual Studio is an integrated • development environment published by Microsoft for writing Windows programs. • .NET can also be used to write managed applications in C#, C++, Visual Basic and any other language • Visual Studio .NET and the .NET Framework as different products.

  37. .Net Execution C++ C# Source code VB complier complier Compilation complier assembly assembly assembly MSIL Common Language Runtime / Just-In-Time Complier Execution Managed code Managed code Managed code Native code Unmanaged code CLR Service Operating system service

  38. Assembly: -Logical unit of deployment, also contains metadata, MSIL and resources. • Microsoft Intermediate Language (MSIL or IL): -CPU independent language. • Metadata: -Structured Information (class or method definition, properties etc). • Managed Code: -Any code that targets the CLR. -Any .Net Language ,including c# ,c++, Visual Basic etc. • JIT-Complier: -All managed code runs in native Language. • Operating System: -your working system.

  39. using System; //Namespace declaration class Sample //class Declaration { static void Main() //method { Console.write(“Hello”); } } OUTPUT: Hello The compilation saved with .cs extension which in this case is “ Sample.cs” Namespace: -elements designed to help you organize the program. -avoid clashes between two sets of code. Class Declaration: -contains data and methods definition that you use in your program. Method: -It tells what this class will do when executed. -Main, is always considered as entry point. Outlet: -console is a class in system namespace. -and write is a method in console class. -the (.)separates subordinate elements. -namespace.class.method=pattern Sample

  40. Literal Variables And Data Type

  41. Contents: • Literals • Data Types • Reference And Value Type • Boxing And Unboxing

  42. Literals • Literals are value constants assigned to variables .C# supports several types of literals. • Boolean True or False • String Sequence of Character. Eg: “ HELLO”. • Character Single Character, Simple-escape Sequence like below Eg: ‘a’ , \a \’ \r \” • Real Decimal Digits, Sign like +,-. • Integer Decimal Digits, Hexadecimal Digits like below 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F Literals Boolean Integer Character String Real

  43. Integer: Int , uint 32-bit, Long , ulong 64-bit, Short , ushort 16-bit, Sbyte , byte 8-bit. Floating Point: Float 32-bit, Double 64 bit. Charactar and String: Char 16-bit unicode String-set of unicode Type Conversion int i = 5; double d = 3.2; string s = “432”; Implicit conversion d = i; Cast required i = (int)d; Conversion required i = System.Convert.Toint32(s); Data Types

  44. Value And Reference Type Value Type • Directly contain data. • Allocated on Stack. • Eg: Structs,Enums Reference Type • Contains reference to object. • Allocated on Heap using new keyword. • Eg:Classes,Interface Ex: int a=1; Ex: object ob=a

  45. Converting value type to reference type is called Boxing. Converting reference to value type is called UnBoxing. Boxing And UnBoxing • Eg: int a=1; //boxing • object ob=a; • int j=(int)ob; //unboxing

  46. Methods & Properties

  47. Methods • Kinds of Methods • Properties Contents:

  48. Methods • Any class has methods and properties. • These are the places where business logic or functionally is written and executed. • Method is declared as: Return-type methodname ( Parameterslist ); Example:Int Addition(int x,int y){} • Int--- Return-type • Addition---methodname • Int x,int y---parameters list

  49. Kinds Of Methods There are two kinds of method: • Instance method: This method is called by creating object of that class which contains the method. • Static Method: This method is called by the classname in which the method is located. We should use the keyword “static” for this method. Syntax: Classname.methodname(); • We can declare the signature of the same method once again in the same class but with different parameters. The parameters should be different.This is called “method overloading”.

More Related