如何在winform中的应用程序中提供变量? [英] How to make a variable availabe across an application in winform?

查看:81
本文介绍了如何在winform中的应用程序中提供变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1。我有一个带有两个dll的应用程序(比如dll_one,dll_two)。

2. dll_One是dll_two中提到的

3. dll_two执行一些处理并计算出一个值可用变量说'Var_Dll_2'

4.当我从winform访问dll_one的对象时,变量'Var_Dll_2'也应该在dll_one中可用。



如何实现这一目标?请建议解决方案

1. I have an application with two dlls (say dll_one,dll_two).
2. dll_One is refered in dll_two
3. The dll_two does some process and a calculated value is made available in a variable say 'Var_Dll_2"
4. When i access dll_one's object from winform , the variable 'Var_Dll_2" should be availabe in dll_one too.

How to achieve this?Please suggest a solution

推荐答案

不要托盘来共享变量,共享值或对象。

有几种方法:

1)任何assambly(忘记.net中的经典dll概念)都可以根据需要定义任意数量的类。因此,使用静态属性定义静态类,并使用它来共享值或对象。不过,出于多种原因,这不是一个好方法。

2)你可以通过引用将参数传递给方法(这是对象的默认值)。

3)你可以按值传递参数(标量)并从函数中获取结果。

请注意,变量本身并不有趣,因为它只保留对值的引用(如果它是一个对象) - 但是推荐本身。您可以根据需要保留对象的多个引用。因此,任何对象都可以保存对任何对象的引用,并且具有该引用的任何方法都将能够改变或读取该对象,而不管变量是什么。并不重要的是你如何在各种大会上发表你的课程。
Don't tray to share variables, share values or objects.
There are several approaches:
1) Any assambly (forget classic dll concept in .net), can define as many classes as you want. So define a static class with a static property and use it to share the value or object. Still, this is not a good approach for many reasons.
2) You can pass parameters to methods by reference (this is default for objects).
3) You can pass parameters by value (scalars) and get results from functions.
Please note, that not the variable itself is interesting, since it is holding only a reference to the value (if it is an object) - but the refernce itself. You can keep as many references to an object as you want. Thus any object can hold a reference to any object, and any method having that reference will be able to change or read that object, indifferent of what the variable is. And does not matter how do you distruburte your classes around assamblies.


这篇关于如何在winform中的应用程序中提供变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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