为所有程序创建对象 [英] creating object for all the program

查看:77
本文介绍了为所有程序创建对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个对象,我希望它在内存中保留整个程序。

但是在块的最后它死了。

i想要创建对象并给予ram并将其保留在程序

i want create an object and i want it stay all over the program in memory.
but in end of the block its die.
i want creat object and give it ram and stay it over the program

推荐答案

看看 Singleton 设计模式。

一个静态类也可以是一个选项。

但不要忘记考虑该对象的目的:你想要吗?误用它来替换旧的VB6的全局变量?然后考虑一个完全不同的设计。
Take a look at the Singleton design pattern.
A static class could also be an option.
But do not forget to consider the purpose of that object: do you want to mis-use it for replacing old VB6's global variables? Then rather consider a totally different design.


使用静态类:参见静态类和静态类成员(C#编程指南) [ ^ ]。
Use a static class: see "Static Classes and Static Class Members (C# Programming Guide)"[^].


这篇关于为所有程序创建对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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