Beruflich Dokumente
Kultur Dokumente
1
Visual Studio 6 VB 6.0
Visual Studio .NET 2002 VB 7.0 (.NET 1.0)
Visual Studio .NET 2003 VB 7.1 (.NET 1.1)
Visual Studio 2005 VB 8.0 (.NET 2.0)
Visual Studio 2008 VB 9.0 (.NET 3.5)
Dim x8
x8 = 9900100200
2
„ --- VB 8.0
Dim n As Nullable(Of Integer) = Nothing
Dim m As Integer
If (n.HasValue) Then
m = n.Value // c# 2.0
Else int? n = null;
m=0 int m = n ?? 0;
End If
„ --- VB 9.0
Dim n As Integer? = Nothing
Dim m = If (n, 0)
GreatFriends VTALKS #8 The New VB 2008 Language Features 5
3
Dim n = 120
Dim d = 4
Dim X1 = n / d
Dim X2 = If(d <> 0, n/d, 0)
Dim X3 = Iif(d <> 0, n/d, 0)
d=0
Dim X4 = n / d
Dim X5 = If(d <> 0, n/d, 0)
Dim X6 = Iif(d <> 0, n/d, 0)
What are the X‟s result value and its data type?
Class Ticket
Public UserName As String
Public MessageId As Integer
Named Type
End Class
{ Initializer List … }
GreatFriends VTALKS #8 The New VB 2008 Language Features 8
4
Class Ticket
Public UserName As String
Public MessageId As Integer
Public Sub New(UserName As String)
Me.UserName = UserName
End Sub
End Class
Class Ticket
Public UserName As String
Public MessageId As Integer
Public TicketString As String
End Class
5
Public Class Message
Public Id As Integer
Public DateCreated As Date
End Class
Class Ticket
Public Owner As String
Public Msg As Message
Public TicketString As String
End Class
6
Imports System.Runtime.CompilerServices
<Extension()> _
Public Function Bold(ByVal text As String) As String
Return ("<b>" & text & "</b>")
End Function
<Extension()> _
Public Function ToCommaList(ByVal arr() As String) As String
If (arr.Length = 0) Then Return (String.Empty)
Dim out As New StringBuilder()
out.AppendFormat("Found {0} items:", arr.Length)
out.AppendLine()
out.Append(arr(0))
For n As Integer = 1 To arr.Length - 1
out.Append(", " & arr(n))
Next
out.AppendLine(".")
Return (out.ToString())
End Function
7
<Extension()> _
Public Function ToLines(ByVal raw As String) As String()
Dim lines() As String
lines = raw.Split(New Char() {Chr(10), Chr(13)}, _
StringSplitOptions.RemoveEmptyEntries)
Return (lines)
End Function
Lambda expression:
Function (num As Integer) num + 1
8
A lambda expression is a function without a name that
calculates and returns a single value.
Lambda expression:
Function (num As Integer) num + 1
Result:
Found 6 items:
one, two, four, five, six, nine.
9
Dim numbers() As String = New String() { _
"one", "two", "three", "four", _
"five", "six", "seven", "eight", "nine"}
Think in your head:
For Each n In Number …
Dim q = From n In numbers _
Where n.Length <= 4
Dim q = numbers _
.Where(Function(n) n.Length <= 4) _
.Select(Function(n) n)
Debug.Print(q.ToCommaList())
GreatFriends VTALKS #8 The New VB 2008 Language Features 19
10
It’s time for questions and answers.
11