如何在所有类中使用单个即时课程 [英] How to use single instant of class in all classes

查看:70
本文介绍了如何在所有类中使用单个即时课程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个项目中有多个类,假设c1,c2,c3。

我想制作c1的单个实例,可以在c2和c3中使用。

我该怎么办?

I have multiple classes in one project suppose c1,c2,c3.
I want to make single instance of c1 which can be used in both c2 and c3.
What should i do?

推荐答案

使用Singleton Class ..并且只实例化一次并将其用于所有后续类。



有两种方法。单身或静态。

下面的链接提供最佳说明,请根据您的需要查看并申请。



http://www.dotnetperls.com/singleton-static [ ^ ]
Use Singleton Class.. and instantiate only once and use it for all your subsequent classes.

There are two approaches. Singleton or Static.
Best explanation is provided in below link check it out and apply as per your need.

http://www.dotnetperls.com/singleton-static[^]


SingelTon是一种设计模式,用于实现您在此处尝试的操作。

请参阅此链接 [ ^ ]和 this [ ^ ]。



希望这对你有所帮助。



问候,

RK
SingelTon is a Designing pattern that is used to achieve what you are trying to do here.
Refer this link[^] and this[^].

Hope this helps you a bit.

Regards,
RK


这篇关于如何在所有类中使用单个即时课程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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