a better way to keep temporary data

dhj

Regular
Joined
Sep 18, 2003
Messages
82
Location
Sri Lanka
hi all
i need to keep some temporary data untill final confirmation
i thought of keeping them in an array
but i found out i cannot set array size dynamically in C# and that need to be given when initializing the array
since i don't know how many elements are there in design time i cannot use array for above process

so can anybody tell me a better way to keep my data temporary untill final confirmation
in what ever the method i need the facility to add and remove data from it too

this is in a web application developing from asp.net and c#

thank you very much in advance
 
You may want to look at one of the classes under System.Collections

an ArrayList may be a easy option for you in this case as it provides nice easy Add, Remove etc methods.
 
thanks
yes i can use a arraylist
but can i add more than one value to a arraylist
eg
1-->john,30,pass
2-->peter,25,fail
3-->Lucky,55,pass

can i add these type of dataset to an array list?

and i want to know how can i get the values from the arraylist

say i need to print peter from above list
how can i do that ?

thank you
 
Easiest way is create a class that has 3 properties (e.g. Name, Score, Status) and store instances of the class in the ArrayList.

Visual Basic:
  Public class Test
  'These really should be properties rather than public vars
      public Name as string
      public Score as integer
      public Pass as boolean
  End Class
  
  'Elsewhere you could now do code like
  Dim a as new ArrayList
  Dim i as new Test
  i.Name = "John"
  i.Score=30
  i.Pass=true
  a.Add(i)
  'etc.
 
 'to get to an item use
 i=a(0)

if you need to refer to items in the arraylist it would be a(0).

You may also find one of the other collection classes useful such as a HashTable - the following is an updated version of the above code...
Visual Basic:
   Public class Test
   'These really should be properties rather than public vars
       public Name as string
       public Score as integer
       public Pass as boolean
   End Class
   
   'Elsewhere you could now do code like
   Dim h as new HashTable
   Dim i as new Test
   i.Name = "John"
   i.Score=30
   i.Pass=true
 h.Add(i.Name, i)
   'etc.
  
  'to get to an item use
  i=h("John")
 'or
 i=h(0)
 
Back
Top