本文整理汇总了VB.NET中System.Predicate<T>代理的典型用法代码示例。如果您正苦于以下问题:VB.NET Predicate<T>代理的具体用法?VB.NET Predicate<T>怎么用?VB.NET Predicate<T>使用的例子?那么, 这里精选的代理代码示例或许可以为您提供帮助。
在下文中一共展示了Predicate<T>代理的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Drawing
Public Class Example
Public Shared Sub Main()
' Create an array of Point structures.
Dim points() As Point = { new Point(100, 200), new Point(150, 250),
new Point(250, 375), new Point(275, 395),
new Point(295, 450) }
' Define the Predicate(Of T) delegate.
Dim predicate As Predicate(Of Point) = AddressOf Example.FindPoints
' Find the first Point structure for which X times Y
' is greater than 100000.
Dim first As Point = Array.Find(points, predicate)
' Display the first structure found.
Console.WriteLine("Found: X = {0}, Y = {1}", first.X, first.Y)
End Sub
Private Shared Function FindPoints(obj As Point) As Boolean
Return obj.X * obj.Y > 100000
End Function
End Class
输出:
Found: X = 275, Y = 395
示例2: Main
' 导入命名空间
Imports System.Drawing
Public Class Example
Public Shared Sub Main()
' Create an array of Point structures.
Dim points() As Point = { new Point(100, 200), new Point(150, 250),
new Point(250, 375), new Point(275, 395),
new Point(295, 450) }
' Find the first Point structure for which X times Y
' is greater than 100000.
Dim first As Point = Array.Find(points,
Function(x) x.X * x.Y > 100000 )
' Display the first structure found.
Console.WriteLine("Found: X = {0}, Y = {1}", first.X, first.Y)
End Sub
End Class
输出:
Found: X = 275, Y = 395
示例3: New
' 导入命名空间
Imports System.Collections.Generic
Public Class HockeyTeam
Private _name As String
Private _founded As Integer
Public Sub New(name As String, year As Integer)
_name = name
_founded = year
End Sub
Public ReadOnly Property Name As String
Get
Return _name
End Get
End Property
Public ReadOnly Property Founded As Integer
Get
Return _founded
End Get
End Property
End Class
Module Example
Public Sub Main()
Dim rnd As New Random()
Dim teams As New List(Of HockeyTeam)()
teams.AddRange( { new HockeyTeam("Detroit Red Wings", 1926),
new HockeyTeam("Chicago Blackhawks", 1926),
new HockeyTeam("San Jose Sharks", 1991),
new HockeyTeam("Montreal Canadiens", 1909),
new HockeyTeam("St. Louis Blues", 1967) } )
Dim years() As Integer = { 1920, 1930, 1980, 2000 }
Dim foundedBeforeYear As Integer = years(rnd.Next(0, years.Length))
Console.WriteLine("Teams founded before {0}:", foundedBeforeYear)
For Each team in teams.FindAll( Function(x) x.Founded <= foundedBeforeYear )
Console.WriteLine("{0}: {1}", team.Name, team.Founded)
Next
End Sub
End Module
输出:
Teams founded before 1930: Detroit Red Wings: 1926 Chicago Blackhawks: 1926 Montreal Canadiens: 1909