Sie sind auf Seite 1von 36

.

NET Framework
Before .NET
• Windows GUI development: Win32 API,
MFC, Visual Basic
• Web development: ASP
• Java – “Write once, run anywhere.”
• Embrace and extend: Visual J++
.Net Framework
• A set of approximately 3500 classes.

• Classes are divided into namespaces grouping similar classes.

• For organization, each class belongs to only one namespace.

• Most classes are lumped into a name space called System


– System.Data: DB access
– System.XML: reading/writing XML
– System.Windows.Forms: Forms manipulation
– System.Net: network communication.
.Net Framework
• Supports Web Standards
– HTML
– XML
– XSLT
– SOAP
– WSDL (Web Services)

• ADO.Net: ActiveX Data Objects

• ASP.Net: Active Server Pages

• ILDASM: A tool used to properly display IL in a human readable


format.

• .Net Compact Framework (mobile devices)


The .NET Framework
VB C++ C# JScript …

Common Language Specification

Visual Studio.NET
ASP.NET: Web Services Windows
Windows
and Web Forms Forms
Forms

ADO.NET: Data and XML

Base Class Library

Common Language Runtime


Common Language Runtime

(CLR)
A common runtime for all .NET languages
– Common type system
– Common metadata
– Intermediate Language (IL) to native code compilers
– Memory allocation and garbage collection
– Code execution and security
• Over 15 languages supported today
– C#, VB, Jscript, Visual C++ from Microsoft
– Perl, Python, Smalltalk, Cobol, Haskell, Mercury, Eiffel,
Oberon, Oz, Pascal, APL, CAML, Scheme, etc.
• Rational is working on Java compiler for CLR
Common Language Runtime

(CLR)
Enables cross-language interoperability
– Common Language Specification describes
interoperability requirements
• Language/Hardware/OS Independent
– Compact framework for small devices
• Industrial strength Garbage collector
– Designed for multi-processor servers
http://en.wikipedia.org/wiki/Image:Overview_of_the_Common_Language_Infrastructure.png
Comparison to Java

compile execute
Hello.java Hello.class JVM

Source code Byte code

compile execute
Hello.vb Hello.exe CLR

Source code CIL


.NET Framework Libraries
• Single consistent set of object oriented
class libraries to enable building distributed
web applications (Unified Classes)

• Built using classes arranged across logical


hierarchical namespaces
– For example: System.Data.SQL

• Work with all CLR languages


– No more “VBRun” or “MFC” divide
What is .Net?
• New programming methodology
– Multiple Languages (VB.Net, C#, J#, Cobol.Net, etc.)
– JIT Compiler

• Primary Parts:
 .Net Framework
 Common Language Runtime (CLR)

• RTM:
– 2002 (v1.0)
– 2003 (v1.1)
– 2005 (v2.0)
.Net Programming Languages
1. Visual Basic.Net 13. RPG
2. C# 14. Component Pascal
3. APL 15. Mercury
4. Fortran 16. Scheme
5. Pascal 17. Curriculum
6. C++ 18. Mondrian
7. Haskell 19. SmallTalk
8. Perl 20. Eiffel
9. Java Language 21. Oberon
10.Python 22. Standard ML
11.COBOL 23. Forth
12.Microsoft JScript 24. Oz
Advantages of .Net
• Write once, run everywhere

• Multiple programming languages (20+)

• Coding Reduction
– Controls
– Template projects
– IIS/Cassini support

• Ease of Deployment

• Security Features
– Evidence-based security
– Code access security
– The verification process
– Role-based security
– Cryptography
– Application domains
Introduction to VB.Net
• VB .Net is developed by Microsoft
• It is Visual Basic for .Net Platform
• Ancestor of VB .Net is BASIC
• In 1991, Microsoft added visual components to
BASIC and created Visual Basic
• After the development of .Net, VB was added
with more set of controls and components and
thus evolved a new language VB .Net
Features of VB .Net
• Object Oriented Language
• We can drag controls from the tool bar and
drop them on the form and write code for
the controls
• Runs on the CLR (Common Language
Runtime)
• Release of unused objects taken care by
the CLR
VB.NET Language Essential
----For Non-VB Programmers
• Projects Types
– Three most commonly used:
• Windows Forms
• Web Forms
• Console Applications
Collapsed Regions
Tabs
Method List

Class
List

Collapsed
Region

Collapsed
Procedure
Creating VB .Net Project in VS 2005

• Open Visual Studio 2005


• Click File -> New -> Project
• Choose Language as VB .Net
• Choose Type (Either Console Application
or what ever we want)
• Give the path under which the project
need to be saved
• Click OK
Input and Output
• Under the namespace System there is a class
called Console
• Console has 2 methods
• ReadLine() – Reads a line from the user
• WriteLine() – writes as line to the screen

• Name spaces can be included in our code using


the keyword imports
• Eg:
Imports System.Console
Data types and Operators in VB .Net

• Data types
– Integer, string, single, double, boolean, char

• Operators
– Arithmetic (+,-,*,/,\,Mod)
– Logical (Or, And)
– Relational (=,<>,<,<=,>,>=)
If Else
If (Condition)
Then
Statements executed if condition is true
Else
Statements executed if condition is false
EndIf

We can also have Else If block in If Else


statements
Statement: If…Else
Module Module1
Sub Main()
Dim intInput As Integer
System.Console.WriteLine(“Enter an interger…”)
intInput=Val(System.Console.ReadLine())
If intInput=1 Then
System.Console.WriteLine(“Thank you!”)
ElseIf intInput=2 Then
System.Console.WriteLine(“That’s good!”)
Else
System.Console.WriteLine(“Not a right number!”)
End If
End Sub
End Module
Select Case
Select Case var
Case 1
stmt1 // executed if var = 1
Case 2
stmt2 // executed if var = 2
Case Else
stmt3 // executed if var is other than 1 and 2
End Select
Statement: Select Case
Module Module1
Sub Main()
Dim intInput As Integer
System.Console.WriteLine(“Enter an interger…”)
intInput=Val(System.Console.ReadLine())
Select Case intInput
Case 1
System.Console.WriteLine(“Thank you!”)
Case 2
System.Console.WriteLine(“That’s good!”)
Case 3 To 7
System.Console.WriteLine(“OK”)
Case Is> 7
System.Console.WriteLine(“Too Big”)
Case Else
System.Console.WriteLine(“Not a right number!”)
End Select
End Sub
End Module
For Loop
For <<var>> = start To end Step <<val>>
Statements
Next

Eg
For I = 1 To 10 Step 2
Console.WriteLine(I)
Next
Here the values printed will be 1,3,5,7,9
Loop Statement: For
• Syntax:
For index=start To end [Step step]
[statements]
[Exit For]
[statements]
Next [index]
• E.g.
Module Module1
Sub Main()
Dim loopIndex As Integer
For loopIndex=0 to 3
System.Console.WriteLine(“Hello!”)
Next loopIndex
End Sub
End Module
Do While Loop
1. Do While(a<>0)
Console.Writeline(a)
a=a–1
Loop
2. Do
Console.Writeline(a)
a=a–1
Loop While(a<>0)
Loop Statement: Do
• Syntax:
Do [While|Until] condition]
[statements]
[Exit Do]
[statements]
Loop
• E.g.
Module Module1
Sub Main()
Dim strInput As String
Do Until Ucase(strInput)=“Stop”
System.Console.WriteLine(“What should I do?”)
strInput=System.Console.ReadLine()
Loop
End Sub
End Module
Loop Statement: For Each…
Next
• Syntax:
For Each element In group
[statements]
[Exit For]
[statements]
Next element
• E.g.
Sub Main()
Dim intArray(2), intItem As Integer
intArray(0)=0
intArray(1)=1
intArray(2)=2
For Each intItem In intArray
System.Console.WriteLine(intArray)
Next intItem
End Sub
Do Until Loop
1. Do Until(a=0)
Console.Writeline(a)
a=a–1
Loop
2. Do
Console.Writeline(a)
a=a–1
Loop Until(a=0)
Changes in VB Language
(cont.)
• When calling procedures, must use
parentheses.
• Parameters are by default passed by value,
instead of by reference.
• Supports constructors and destructors for use
when initializing an object of a class.
• If…Then statements are now short-circuited.
Loop Statement: While
• Syntax:
While condition
[statements]
End While
• E.g.
Sub CheckWhile()
Dim intCounter As Integer =0
Dim intNumber As Integer =10
While intNumer>6
intNumber-=1
intCounter+=1
End While
MsgBox(“The loop ran “ & intCounter & “ times.”)
End Sub
Like a Loop: With
• Syntax:
With object
[statements]
End With
• E.g.
With TextBox1
,Height = 1000
.Width = 3000
.Text = “Welcome, World!”
End With
Like With: Enumerations
• E.g.
Module Module
Enum Days
Sunday=1
Monday=2
Tuesday=3
Wednesday=4
End Enum

Sub Main()
System.Console.WriteLine(“Monday is day “ & Days.Monday)
End Sub
End Module

Das könnte Ihnen auch gefallen