dhj Posted March 16, 2004 Posted March 16, 2004 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 Quote
Administrators PlausiblyDamp Posted March 16, 2004 Administrators Posted March 16, 2004 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
dhj Posted March 17, 2004 Author Posted March 17, 2004 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 Quote
Administrators PlausiblyDamp Posted March 17, 2004 Administrators Posted March 17, 2004 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) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.