Introduction to DOT NET - PowerPoint PPT Presentation

1 / 52
About This Presentation
Title:

Introduction to DOT NET

Description:

comment. */ Line termination. Value = a b c. Conciseness. If (condition == true) ... Comments used for project documentation only (not executable). Begin with ... – PowerPoint PPT presentation

Number of Views:4698
Avg rating:3.0/5.0
Slides: 53
Provided by: kamolkia
Category:

less

Transcript and Presenter's Notes

Title: Introduction to DOT NET


1
Introduction to DOT NET
  • Lecture 1

2
Today Topics
  • Microsoft.NET Framework
  • VB.NET Introduction

3
The .NET Framework
  • Chapter 1

4
What Really is .NET?
  • Software Technology
  • connecting
  • People
  • information
  • systems
  • devices

5
What Really is .NET?
  • Write Once

Connect Everywhere to Every Device
6
What Really is .NET?
.NET Framework a structure or an environment
for framing problems and facilitating effective
decisions.
Application development
Build
Deploy
Run
7
.NET Terms in 1-3-5
  • A way to accelerate this one move to distributed
    computing.
  • Three levels to make distributed computing
    happen, which are
  • Everything is a Web service,
  • Ability to aggregate and integrate Web services
  • Ability to Deliver simple, compelling user
    experiences
  • Five things to address .NET
  • Developer Tools .NET framework and Visual Studio
    tools to make writing web service as simple and
    as easy as possible
  • Servers set of .NET servers to aggregate and
    deliver web services
  • .NET building block services
  • Device Software
  • User experiences

8
The .NET Framework
Framework Services
VB
C
C
Visual Studio.NET
JScript

Common Type Specification
4.ASP.NET Web Services and Web Forms
WindowsForms
3. ADO.NET Data and XML
2. Base Class Library
1. Common Language Runtime
9
The .NET Framework
VB
C
C
JScript
  • The .NET languages C, VB.NET, C, J, Jscript,
    and etc.

10
The .NET Framework
Common Type Specification
  • Common Type Specification or Common Language
    Specification
  • A subset of .Net supported types
  • A set of guidelines to write languages that run
    under the CLR (Common Language Runtime).
  • A complete list of rules for the CLS in the .NET
    Framework SDK documentation

11
The .NET Framework
  • ASP.NET the platform allowing web applications
    and Web Services to be programmed in any .NET
    language.

4.ASP.NET Web Services and Web Forms
WindowsForms
Framework Services
3. ADO.NET Data and XML
  • ADO.NET the platform allowing any .NET language
    to do database programming

12
The .NET Framework
  • The .NET class library collection of pre-built
    functionalities. Sometimes organized into
    technology sets such as ADO.NET and Windows Forms

2. Base Class Library
13
Based Class Library
  • Collections of commonly used code providing
    general functions being accessed from any
    application.
  • Namespaces Logical groups of code are
    organized called Libraries contain fundamental
    code structures and methods that allow you to
    communicate with the operating system software
    and other applications
  • The code in libraries can be reused across
    applications

ADO.NET Data Class
Windows forms
Web Forms
XML
File I/O

Core system classes (threading,
serilazation, Reflection, collections, and so on)
The .Net Class Library
  • The actual library of code is located in one or
    more dynamic link library files such as
    System.data.dll

14
.NET Base Class Library
15
.NET Base Classes (continued)
16
The .NET Framework
  • The Common Language Runtime (CLR) .NET runtime
    engine that executes all .NET programs. Also
    provides automatic memory management, security,
    optimization, and garbage collection. The .NET
    languages are compiled to the same intermediate
    language, known as MS Intermediate Language (MSIL
    or IL).

1. Common Language Runtime
17
Common Language Runtime
  • Each .NET language provides a compiler that
    supports the CLR.
  • No more DLL hell IL programs store extra info
    (Metadata) about their classes and the
    components.
  • CLR can load more than one version of a component
    at a time.
  • CLR monitors memory, automatically removes unused
    objects with its garbage collection.

Compiler and Loader
Code verification and optimization
Memory management garbage collection
Code access security
(other managed code services
The Common Language Runtime
18
Language compilation in .NET
Code in VB.NET
Code in C
Code in another .NET Language
VB.NET compiler (vbc.exe)
C compiler (csc.exe)
Appropriate compiler
MSIL code
Deep language integration all .NET languages are
compiled to MSIL (intermediate language).
CLR Just-in-time execution
19
The .NET Framework
  • Visual Studio .NET optional development tool
    containing a rich set of productivity and
    debugging features

Visual Studio.NET
20
The .NET Languages
  • Chapter 2 and 3

21
The .NET Languages
  • The .NET framework ships with three code
    languages Visual Basic, C, and Jscript.
  • .NET also allows other third-party developers to
    release languages (Eiffel, Perl, Python, Cobol)
    by copy the compiler to your computer and add a
    line to the configuration file in machine.config
  • Almost any line in VB.NET and C can be convert
    into an equivalent line in the other.
  • Chapter 2 provides a brief overview of language
    overview of both VB.NET and C

22
Basic Difference Between C and VB.NET
  • VB .NET
  • - Not case-sensitive
  • Commenting
  • a VB comment
  • Line termination
  • Value a b _
  • c
  • Conciseness
  • If condition true Then
  • ..
  • End if
  • C
  • - Case-sensetive
  • Commenting
  • // c commenting
  • / A multi-line
  • comment. /
  • Line termination
  • Value a b
  • c
  • Conciseness
  • If (condition true)
  • ..

23
Types, Objects, and Namespaces (Chapter 3)
  • The basics about classes
  • Advanced Class Programming
  • Namespaces and Assemblies

24
The Basics About Class
  • Classes are the definitions of objects class can
    be used to create many instances of the class
    called objects.
  • Class Components
  • Properties store info about an object
  • Methods action within an object, methods are
    used for compound actions that perform a distinct
    task or may change the objects state
  • Events provide notification from the control
    that something has happened
  • Classes also contain their own code and internal
    set of private data.

25
Shared Members
  • There are two ways to use .NET classes
  • Creating an object first
  • Dim SaleProduct As Product
  • SaleProdcut New Product()
  • Use class member without creating an object
    ?Shared Members which can be accessed by class
    name eg. DateTime.Now without creating a DateTime
    instance first.
  • Dim MyDate As DateTime DateTime.Now
  • Some class can be used both shared member and
    instance member (DateTime class)

26
A simple class and Property
  • Public Class Product
  • Private _Name As String
  • Private _Price As Decimal
  • Private _ImageUrl as String
  • Public Property Price() As Decimal
  • Get
  • Return _Price
  • End Get
  • Set (Value As Decimal)
  • _Price Value
  • End Set
  • End Property
  • Public Property ImageUrl() As String
  • ..
  • End Property
  • Public Property Name() As String

Define private variables (class Variables)
  • We can make the member variable as public but it
    would allow the client code freely access to
    change any variables. Instead we create property
    procedures to manipulate the code
  • Property procedures have two parts
  • Procedure to retrieve data
  • Procedure to set data

27
A Basic Method
  • Public Class Product
  • Private _Name As String
  • Private _Price As Decimal
  • Private _ImageUrl as String
  • Public Function GetHtml() As String
  • Dim HtmlString As String
  • htmlString "lth1gt" _Name "lt/h1gtltbrgt"
  • htmlString "lth3gtCosts "
    _Price.ToString() Baht lt/h3gtltbrgt"
  • HtmlString "ltimg src" _ImageUrl
    "gt"
  • Return HtmlString
  • End Function
  • Public Property Price() As Decimal
  • ..
  • End Property
  • Public Property ImageUrl() As String
  • ..

You can add a method to a class by adding a
public function or subroutine to a class. The
product class has GetHtml method that returns a
string representing a formatted block of HTML.
This HTML can be placed on a web page to
represent the product.
28
Create and configure the class
  • lt
  • Dim SaleProduct As New Product()
  • SaleProduct.Name PadThai Dish"
  • SaleProduct.Price 50
  • SaleProduct.ImageUrl "http//localhost/WebSample
    s/home/padthai.jpg"
  • Response.write(SaleProduct.GetHtml()) gt

Create Object
Call propertyName, Price And ImpageUrl
Call method GetHtml
29
Result
30
Constructors
  • Product class could have an error if getHTML is
    used but the data has not been supplied.
  • Constructor is a special method run when the
    class is first created
  • In C, a constructor is the name of the class
  • In VB.NET, the constructor always has the name
    New.
  • .NET supplies a default constructor that does
    nothing.

31
Product Class with Constructor
  • Public Class Product
  • Public Sub New (name As String, price As Decimal)
  • _Name name
  • _Price price
  • End Sub
  • End Class
  • To create a Product Object, you need to supply
    info for these parameters, ensuring it will start
    its life with valid information.
  • Dim SaleProduct As New Product (Kitchen
    Garbage, 49.99)

32
Advanced Class Programming
  • Inheritance allow one class to acquire and
    extend the functionality of another class
  • You could create a class called TaxableProduct
    that inherits from Product class. TaxableProduct
    class automatically has all the same methods and
    properties as in Product class
  • Shared Members shared properties and methods
    without a live object
  • MyVal Math.Sin(AngleInRadians)
  • To create a shared properties or method, Shared
    (or static in c) keyword is use
  • Public Shared ReadOnly Property TaxRate() As
    Decimal
  • End Property
  • Casting converting class into different data
    tytes

33
Namespaces and Assemblies
  • Namespaces Every piece of code in .NET exists
    inside a class. And every class exists inside a
    namespace.
  • Assemblies all .NET classes are contained in
    assemblies which is the .NET equivalent of
    traditional .exe and .dll files. Two ways to use
    assemblies
  • Placing it in the same directory or in a
    subdirectory of the application
  • Placing it in the Global Assembly Cache (GAC), a
    system wide store of shared assemblies. All .NET
    classes are a part of the GAC
  • Chapter 21 for more detail

34
Namespace
  • The base class libraries are organized into
    logical groupings of code called namespaces
  • Namespaces simplify programming by allowing the
    developer to call methods in the namespace as if
    they were methods in the application.
  • The System object is at the top of the namespace
    hierarchy, and all objects inherit from it
  • ASP.NET System.Web namespace
  • WebForms System.Web.UI namespace
  • HTML Server Controls System.Web.UI.Control.HTMLCo
    ntrol
  • ASP.NET Server Controls System.Web.UI.Control.Web
    Control
  • MSDN reference contains class library reference
    which documents the properties, methods, and
    events of every class in every name space.

35
(No Transcript)
36
Visual Basic Programming
37
Steps for Writing VB Projects
  • Design/Define the User Interface
  • Plan/Set the Properties
  • Plan/Write the Code
  • Test and Debug

38
Visual Basic Application Files
VB application can consist of one or more
projects. Each project can contain one or more
form.
39
Visual Studio Environment
  • Where you create and test the project.
  • Integrated development environment (IDE)
  • Form designer ? create form
  • Editor ? entering and modifying codes
  • Compiler ?translating VB codes to IL
  • Debugger ? locate and correct program errors
  • Object browser ? view available classes, objects,
    properties, methods, and events
  • Help ? help facility

40
IDE Main Window
  • Toolbars
  • Document Window ?Form designer, code editor,
    object browser and requested help page.
  • Form Designer ? form for UI
  • Solution Explorer Window ? holds filenames, list
    of classes it references
  • Properties Window ? to set properties of the
    objects
  • Toolbox ? holds tool used to place controls on a
    form

41
IDE Main Window
42
VB Toolbox
  • Holds the tools you place on a form

43
Set Properties - Properties window
Properties window
Namespace and class of selected Object Object ?
Label1 Class? System.Windows.Forms.Label Actual
Class ? Label Namespace ?System.Windows.Forms
Object box
Settings box
Name of selected object
N
44
Write Code
  • VB Events
  • VB will respond to the event and automatically
    execute the procedures.
  • VB ignores events for which no procedures are
    written
  • VB Event Procedures
  • Code in VB is written in procedures.
  • Eg. Private Sub
  • End Sub
  • Automatically named
  • Object name and underscore (_) and the name of
    the event
  • Eg pushButton_Click procedure

45
Editor Window
  • Declarations Section
  • Class list
  • Method list

46
Code Statements
  • Remark statement
  • Comments used for project documentation only (not
    executable).
  • Begin with
  • Good programming practices must include remarks
    to clarify the projects.

47
Code Statements
  • Assignment Statement
  • Assigns a value to a property or variables
  • Operates from right to left
  • Object.Property value
  • Eg. titleLabel.Text Welcome to Class
  • numberInteger 3
  • messageLabel.AutoSize True

48
Code Statements
  • Ending program by executing a method
  • Object.Method()
  • Method always has parenthesis properties dont
  • Eg. helloButton.Hide()
  • messageLabel.Show()
  • To execute a method of the current object (the
    form itself) use Me keyword
  • Me.Close()

49
Finding and Fixing Errors
  • Syntax errors
  • Run-time errors (or Exception)
  • Logic Errors

50
Finding and Fixing Errors
  • Syntax errors
  • Punctuation, format or spelling mistakes
  • Can be identified as you move off the offending
    line with a blue squiggly line appeared under the
    part of the line.

51
Finding and Fixing Errors
  • Run-time errors (or Exception)
  • Project halts during execution
  • Statements that cannot execute correctly cause
    run-time errors.
  • Impossible arithmetic operations (dividing by
    zero)
  • Logic Errors
  • Project runs but produces incorrect results

52
Visual Studio Help
  • Includes all of the Microsoft Developer Network
    library (MSDN)
  • Several books
  • Technical articles
  • Microsoft knowledge base FAQ questions
  • MSDN includes reference materials for the VS IDE,
    the .NET frameword, VB, C, J and C.
  • Viewing the help topics
  • Contents, Index, or Search
  • Context-sensitive help
  • Quick way to view Help
  • Select a VB object or place the insertion point
    in the word in the editor and press F1
Write a Comment
User Comments (0)
About PowerShow.com