ASP.NET Session 3


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • To use this concept in OOP we derived the idea of Class and Object.
  • Encapsulation: Also termed as Information hiding , is the ability to hide the internals of an object from its users and also to provide an interface to only those members which you want the client to manipulate. Inheritance : Specification of relationship of one class with another class. A derived class is the new class being created and the base class is the one from which it is derived . Polymorphism : Its is the functionality that allows old code to call new code. Allows you to extend or enhance your system without having to modify old code.
  • ASP.NET Session 3

    1. 1. C# language Session -3
    2. 2. Objectives 1.Understanding of the language basics to facilitate development. 2.Basic Object Oriented Programming concepts and C# Programming Structure. 3. Language fundamentals 4.Doing our first C# Program. 5. Hands on knowledge in Visual Studio.
    3. 3. Introduction • C# (pronounced “See Sharp”) is a simple, modern, object-oriented programming language. • It was made by Microsoft Corporation, more precisely by Anders Hejlsberg. • It was created to use all capacities of .NET platform. The first version appeared in 2001, last update appeared in 2010 with the C# 4.0. • C# has its roots in the C family of languages and will be immediately familiar to C, C++, and Java programmers.
    4. 4. Fundamentals of Object Oriented Programming • OOPs design methodology is different from traditional language like BASIC, Pascal, C etc. Those are called the Procedural Language. • In OOP, the emphasis is on Data and not on procedures. Class • In OOP, A class describes all the attributes of objects,as well as the methods that implement the behavior of member object. • A class is only a specification of a data type. • A class is like a blue print of the Object.
    5. 5. Fundamentals of Object Oriented Programming(Contd..) Objects • They are instance of classes. • Objects are the central idea behind OOP technology. • An object is a bundle of variables and related methods. • When an object is created memory allocation takes place.
    6. 6. Fundamentals of Object Oriented Programming(Contd..) Three principles of object oriented programming 1.Encapsulation • The ability to hide the internals details of an object from the outside world. 2.Inheritance • Hierarchy is used to define more specialized classes based on a preexisting generalized class. 3.Polymorphism • The ability to extend functionality.
    7. 7. Abstract Class:  We can not create a object of abstract class.  It only allows other classes to inherit from it but can't be instantiated.  In C# we use Abstract Keyword. Interface  An interface is not a class, is entity.  An interface has no implementation; it only has the signature.  Just the definition of the methods without the body.
    8. 8. Partial Class Example • public partial class MyClass • { • partial void DoSomethingElse(); • public void DoSomething() • { Console.WriteLine("DoSomething() execution started."); • DoSomethingElse(); • Console.WriteLine("DoSomething() execution finished.");
    9. 9. • Console.ReadKey(); • } • } • public partial class MyClass • { • partial void DoSomethingElse() • { • Console.WriteLine("DoSomethingElse() called."); • } • }
    10. 10. • class Program • { • • static void Main(string[] args) • { • MyClass mm = new MyClass(); • mm.DoSomething(); • } • } • }
    11. 11. OutPut • DoSomething() execution started. • DoSomethingElse() called. • DoSomething() execution finished.
    12. 12. C# Language Fundamentals • Garbage collection automatically reclaims memory occupied by unused objects. • Exception handling provides a structured and extensible approach to error detection and recovery. • Ex: try, catch & finally • C# is case-sensitive.
    13. 13. C# Console Application • Console applications in C# have exactly the same purpose as regular console applications: to provide a command line interface with the user. • Console applications have three main input streams: standard in, standard out and standard error. • “Hello World” Program using C#: using System; class Hello { static void Main(String[] args) { Console.WriteLine("Hello, World"); } }
    14. 14. C# Console Application in Visual Studio
    15. 15. C# Console Application(Contd..) • The "System.Console" class:- The main element in a console application is the "System.Console" class. It contains all methods needed to control the three streams of data. • "ReadLine" method:- The main ways of acquiring data from the standard input stream. "ReadLine" reads a whole line of characters from the buffer up to the point where the first end line character ("n") is found. It outputs its data as "string“.
    16. 16. Working with Visual Studio • Microsoft Visual Studio is an Integrated Development Environment (IDE) from Microsoft. • It can be used to develop Console applications along with Windows Forms applications, web sites, web applications, and web services. • Features : 1. Code editor 2. Debugger 3. Designer 4. Other Tools
    17. 17. Code editor • Visual Studio includes a code editor that supports syntax highlighting and code completion using IntelliSense for not only variables, functions and methods but also language constructs like loops and queries. • Autocomplete suggestions are popped up in a modeless list box, overlaid on top of the code editor.
    18. 18. Debugger • Visual Studio includes a debugger that works both as a source-level debugger and as a machine-level debugger. • It works with both managed code as well as native code and can be used for debugging applications written in any language supported by Visual Studio. • The debugger allows setting breakpoints (which allow execution to be stopped temporarily at a certain position). • The debugger supports Edit and Continue, i.e., it allows code to be edited as it is being debugged (32 bit only; not supported in 64 bit). • When debugging, if the mouse pointer hovers over any variable, its current value is displayed in a tooltip ("data tooltips"), where it can also be modified if desired.
    19. 19. Designer • Visual Studio includes a host of visual designers to aid in the development of applications. These tools include: 1. Windows Forms Designer 2. Web designer/development 3. Class designer 4. Data designer
    20. 20. Windows Forms Designer • The Windows Forms designer is used to build GUI applications using Windows Forms. • It includes a palette of UI widgets and controls (including buttons, progress bars, labels, layout containers and other controls) that can be dragged and dropped on a form surface. • Layout can be controlled by housing the controls inside other containers or locking them to the side of the form. • Controls that display data (like textbox, list box, grid view, etc.) can be data-bound to data sources like databases or queries. • The designer generates either C# or VB.NET code for the application.
    21. 21. Web designer/development • Visual Studio also includes a web-site editor and designer that allows web pages to be authored by dragging and dropping Web controls. • It is used for developing ASP.NET applications and supports HTML, CSS and JavaScript. • It uses a code-behind model to link with ASP.NET code.
    22. 22. Class designer • The Class Designer is used to author and edit the classes. • The Class Designer can generate C# and VB.NET code outlines for the classes and methods. • It can also generate class diagrams from hand- written classes.
    23. 23. Data designer • The data designer can be used to graphically edit typed database tables, primary and foreign keys and constraints. • It can also be used to design queries from the graphical view.
    24. 24. Polymorphism in .Net • What is Polymorphism? Polymorphism means same operation may behave differently on different classes. Example of Compile Time Polymorphism: Method Overloading Example of Run Time Polymorphism: Method Overriding
    25. 25. Example of Compile Time Polymorphism Method Overloading - Method with same name but with different arguments is called method overloading. - Method Overloading forms compile-time polymorphism. - Example of Method Overloading: class A1 { void hello() { Console.WriteLine(“Hello”); } void hello(string s) { Console.WriteLine(“Hello {0}”,s); } }
    26. 26. Run Time Polymorphism • Method Overriding - Method overriding occurs when child class declares a method that has the same type arguments as a method declared by one of its superclass. - Method overriding forms Run-time polymorphism. - Note: By default functions are not virtual in C# and so you need to write “virtual” explicitly. While by default in Java each function are virtual. - Example of Method Overriding:
    27. 27. • Class parent { virtual void hello() { Console.WriteLine(“Hello from Parent”); } } Class child : parent { override void hello() { Console.WriteLine(“Hello from Child”); } } static void main() { parent objParent = new child(); objParent.hello(); } //Output Hello from Child. •
    28. 28. Summery Language basics to facilitate development. Basic Object Oriented Programming concepts C# Programming Structure. Language fundamentals Doing our first C# Program. Hands on knowledge in Visual Studio.