Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I wrote this method initially to return the values in my generic list. But when i deserialize my data from a binary file into my list then call this method it displays what is in my list, the problem am having is that if i call the method with and event it does not display what is in the list rather it create a new one... Any help please
C#
public Fitness getFitnessClass(int index)
{
    return fitness[index];
}
Posted
Updated 6-Apr-12 4:01am
v2

1 solution

It is difficult to tell, without teh code that actually calls it, but I suspect that you are creating a new instance of the class in the Event handler:
C#
MyClass mine = new MyClass();
Fitness thisOne = mine.getFitnessClass(1);
Normally, you would access such via the existing class index - but if you can't get access to it, then the method and teh list would have to be declared as static In that case you can access the one and only instance of the list via the class name, rather than an instance:
C#
Fitness thisOne = MyClass.getFitnessClass(1);


Even then, it will depend on when you do things: if this is web related, then data is not persisted between pages, or within a page between the original load and a button press or other user interaction unless you explicitly save teh data in the Session or a cookie.
 
Share this answer
 
Comments
IamBlessed 6-Apr-12 10:13am    
Ok thanks.. How do i the save and retrieve the instance of the class from a session..... Thanks
OriginalGriff 6-Apr-12 10:16am    
MSDN can show you: http://msdn.microsoft.com/en-us/library/ms178581.aspx
IamBlessed 6-Apr-12 10:20am    
Thanks I appreciate

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900