问题描述
大家好,
我的项目中有一个MainForm和大约40个DialogForms.还有一个类(以MyClass命名),包含我项目中的大多数方法和过程.我的问题是;
1)在这种情况下,我应该描述MyClass.cs静态还是动态?我认为不同之处在于;静态类方法在首次创建后仍保留在内存中,而动态类方法则由Garbage Collector时不时地选择.另一方面,每次在创建MyClass实例后使用一种方法时,直到GC收集内存使用量都在增加.除此之外,静态类成员保留最后一个值,有时可能很危险.真的吗?我混淆了选择动态还是静态类.
2)如果我将MyClass定义为静态,则还必须使用一些MainForm变量.在这种情况下,我认为我必须使用MainForm的静态成员并将MainForm定义为静态.但是,尽管我试图使MainForm静态化,但我还是没有做到这一点.有错吗?
MainForm.cs:
命名空间MyProject
{
公共 static 局部类MainForm:Form
{
......
在此先感谢...
Hi all,
I have a MainForm and approximately 40 DialogForms in my project. There is also a class (named for ex. MyClass) which contains most of the methods and procedures in my project. My problem is that;
1) In this case, should I describe MyClass.cs Static or Dynamic? I think the diference is that; static class methods remains on memory after first created, and dynamic class methods is coollected by Garbage Collector from time to time. On the other hand, every time I use a method after creating an instance of MyClass, the memory usage is getting increase until GC collected it. In addition to this, static class members keep the last value and sometimes it may be dangerous. Is that true? I am confusing to choice dynamic or static class.
2) If I define MyClass as static, there are also some MainForm variables I have to use. In this case, I think I have to use static members of MainForm and define MainForm as static. But, although I tried to make MainForm static, I have not managed to do like that; Is there a mistake?
MainForm.cs :
namespace MyProject
{
public static partial class MainForm : Form
{
......
Thanks in advance...
推荐答案
这篇关于使用STATIC类问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!