我读到在编写应用时是否应该使用With
关键字。这些意见似乎有所不同(即使是在这个网站上的问题),从它是好的到永远不会使用它。我是VB.NET的新手,来自C#,我一直想知道的具体情况是这个
Public Overloads Function GetHashCode(obj As Package) As Integer Implements IEqualityComparer(Of Package).GetHashCode
With obj
Return IIf(ReferenceEquals(obj, Nothing), 0, 23 * (.Weight.GetHashCode() + .CustomerReference.GetHashCode() + .Dimensions.Height.GetHashCode() +
.Dimensions.Width.GetHashCode() + .Dimensions.Length.GetHashCode()))
End With
'Return IIf(ReferenceEquals(obj, Nothing), 0, 23 * (obj.Weight.GetHashCode() + obj.CustomerReference.GetHashCode() + obj.Dimensions.Height.GetHashCode() +
' obj.Dimensions.Width.GetHashCode() + obj.Dimensions.Length.GetHashCode()))
End Function
这两个Return
语句中的任何一个都有优势吗?我不应该在这里使用With
关键字还是可以吗?