Public Overrides Function GetHashCode() As Integer Public Overrides Function Equals(ByVal obj As Object) As Boolean Public Overloads Function Equals(ByVal other As Box) As Boolean Implements IEquatable(Of Box).Equals Public Sub New(ByVal h As Integer, ByVal l As Integer, ByVal w As Integer) Public Class Box : Implements IEquatable(Of Box) using System īoxCollection bxList = new BoxCollection() Ĭonsole.WriteLine("Contains ", bx.Height.ToString(), bx.Length.ToString(), bx.Width.ToString(), bx.GetHashCode().ToString()) This example also implements an IEnumerator interface for the BoxCollection class so that the collection can be enumerated. The BoxCollection class also provides an overload of the Contains method that takes a specified Equalit圜omparer object, such as BoxSameDimensions and BoxSameVol classes in the example. This method is used by the Add method so that each Box added to the collection has a unique set of dimensions. The BoxCollection class implements the Contains method to use the default equality to determine whether a Box is in the collection. The Box class implements the IEquatable interface to define the default equality as the dimensions being the same. Equality can be defined as all dimensions being the same or the volume being the same. Each Box has height, length, and width properties, which are used to define equality. The following example implements the ICollection interface to create a collection of custom Box objects named BoxCollection.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |