跳到主要內容

發表文章

目前顯示的是 5月, 2010的文章

[.net]IComparable Interface

Sorting Example Imports System.Collections Public Class Temperature Implements IComparable ' The temperature value Protected temperatureF As Double Public Overloads Function CompareTo( ByVal obj As Object ) As Integer _ Implements IComparable.CompareTo Dim otherTemperature As Temperature = TryCast(obj, Temperature) If otherTemperature IsNot Nothing Then Return Me .temperatureF.CompareTo(otherTemperature.temperatureF) Else Throw New ArgumentException( "Object is not a Temperature" ) End If End Function Public Property Fahrenheit() As Double Get Return temperatureF End Get Set ( ByVal Value As Double ) Me .temperatureF = Value End Set End Property Public Property Celsius() As Double Get Return (temperatureF - 32) * (5/9) End Get Set ( ByVal Value As Double ) Me .temperatureF = (Value * 9/5

[.Net] List(Of T).Find (Predicate(Of T))

Find Object in List Method 1 Function PredicatFunction( ByVal tempProduct As Product) as boolean Return tempProduct.ProductID='MyID' End Function Dim MyList As List(Of Product)=new List(Of Product) Dim tmpProduct as Product=MyList.Find(AddressOf PredicatFunction ) Mothod 2 Dim ProductID as String='MyID' Dim MyList As List(Of product)=new List(Of product) Dim tmpProduct as Product=MyList.Find(Function(n) n.ProductID=productID )