如何将值从一个类传递到另一个类并在c#windows应用程序中获取此值 [英] How to pass value from one class to another and get this value in c# windows application
本文介绍了如何将值从一个类传递到另一个类并在c#windows应用程序中获取此值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有用户类和登录表单,在登录时存储用户对象中的用户信息。我还有另一个类名Customer.For添加客户我需要存储在用户类中的客户ID。我怎样才能在windows应用程序中得到它。
解决方案
你可以使它成为一个全局对象并在整个应用程序中共享它,或者你可以向所有构造函数添加一个参数传递对象的表单。
通常你让用户
类提供一个方法(例如getUserId ()
)或只读属性。然后,当然,Customer
对象需要在User
类的实例上调用该方法。
I have user class and login form,in the login time store user information in user object. I have also another class name Customer.For adding a customer i need customer id which is stored in user class. How can i get this in windows application.
解决方案
You can make it a global object and share it across the application or you could add a parameter to the constructors of all the form to pass the object around.
Usually you make theUser
class provide a method (e.g.getUserId()
) or a read-only property. Then, of course, theCustomer
object needs to call the method on a instance of theUser
class.
这篇关于如何将值从一个类传递到另一个类并在c#windows应用程序中获取此值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文