Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

  • Administrators
Posted

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

 

 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...

  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)

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

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...