无论如何请在那里我可以重写此方法 [英] Please is there anyway i can rewrite this method

查看:109
本文介绍了无论如何请在那里我可以重写此方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初编写此方法是为了返回通用列表中的值.但是当我将二进制文件中的数据反序列化到列表中然后调用此方法时,它将显示列表中的内容,问题是,如果我使用和事件调用该方法,则它不会显示列表中的内容,而是创建一个新的...请提供任何帮助

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

public Fitness getFitnessClass(int index)
{
    return fitness[index];
}

推荐答案

,如果没有实际调用它的代码,很难说,但是我怀疑您正在该类中创建该类的新实例.事件处理程序:
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:
MyClass mine = new MyClass();
Fitness thisOne = mine.getFitnessClass(1);

通常,您可以通过现有的类索引进行访问-但如果无法访问它,然后必须将方法和列表声明为static.在这种情况下,您可以通过类名而不是实例来访问列表的唯一实例:

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:

Fitness thisOne = MyClass.getFitnessClass(1);



即使这样,它仍取决于您执行操作的时间:如果这是与Web相关的,则数据不会持久保存在页面之间,或者在原始加载与按钮按下或其他用户交互之间的页面内,除非您明确地将数据保存在页面中.会话或Cookie.



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.


这篇关于无论如何请在那里我可以重写此方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆