Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Private Structure TransactionHistoryStructure

Public TransactionDate As Date

Public TransactionType As String

Public TransactionAmount As Double

End Structure

 

'HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH

Private TransactionHistory As TransactionHistoryStructure

 

thats what i have, i want to make the TransactionHistory an array list of TransactionHistoryStructure 's

  • *Experts*
Posted

You can make a strongly-typed collection by making a class which inherits CollectionBase and then overriding the Item property, the Add method, and the Remove method (those are the bare minimums - you can override other things too, like the Contains method too) and making their parameters and return values TransactionHistoryStructure instead of just Object.

 

Here's a sample of a strongly-typed collection which only accepts Product object:

Public Class ProductCollection : Inherits CollectionBase
   Public Function Add(ByVal obj As Product) As Integer
       Return Me.List.Add(obj)
   End Function

   Public Sub Remove(ByVal obj As Product)
       If Me.List.Contains(obj) Then Me.List.Remove(obj)
   End Sub

   Default Public Property Item(ByVal index As Integer) As Product
       Get
           Return DirectCast(Me.List.Item(index), Product)
       End Get
       Set(ByVal Value As Product)
           Me.List.Item(index) = Value
       End Set
   End Property
End Class

Posted

i guess i am a dummy, but i dont quite understand gotta rub my nose in it i guess

 

this is what i did

 

Public Class TransactionHistoryStructureCollection : Inherits CollectionBase

Public Structure TransactionHistoryStructure

Public TransactionDate As Date

Public TransactionType As String

Public TransactionAmount As Double

End Structure

 

Public Function Add(ByVal obj As TransactionHistoryStructure) As Integer

Return Me.List.Add(obj)

End Function

 

Public Sub Remove(ByVal obj As TransactionHistoryStructure)

If Me.List.Contains(obj) Then Me.List.Remove(obj)

End Sub

 

Default Public Property Item(ByVal index As Integer) As TransactionHistoryStructure

Get

Return DirectCast(Me.List.Item(index), TransactionHistoryStructure)

End Get

Set(ByVal Value As TransactionHistoryStructure)

Me.List.Item(index) = Value

End Set

End Property

Posted

You shouldn't be using structures with ArrayLists. Tons of boxing and unbox is not good. You're better off turning your structure into a class.

 

In any case, using a strucutre inside an ArrayList is the exact same as using any other thing inside an ArrayList.

 

// Your structure. This should really be a class
// if you plan to use it with ArrayLists and not arrays.
public struct MyStruct 
{
  public int Total = 0;
}

// Instantiate an ArrayList.
ArrayList list = new ArrayList();
// Add structure to list.
list.Add(MyStruct);

// Loop through list and print out struct info.
foreach MyStruct s in list {
  Console.Writeline(s.Total);
}

Gamer extraordinaire. Programmer wannabe.
Posted

thanks :)

 

 

when using c++.net consol programs has anyone noticed a lag when they run? and does anyone know how to make the dos window wait after execution?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...