简体   繁体   English

如何维护一个变量中的值并以另一种形式在另一个变量中使用它

[英]How to maintain the value in a variable and use it in another variable in another form

I have two windows form.我有两个窗体。 From form1 I connect to my server and as an output I get session id in a xml form.我从 form1 连接到我的服务器,作为输出,我以 xml 形式获得会话 ID。 I parse the value and store it in a variable name session id.我解析该值并将其存储在变量名会话 id 中。 Now in form2 I need to use the session Id which I received in the previous form .现在在 form2 中,我需要使用我在上一个表单中收到的会话 ID。 How to do it?怎么做? I was making the object of that class and using the data member but as the scope of the program gets over the value in the variable get removed.我正在创建该类的对象并使用数据成员,但随着程序的范围越过变量中的值被删除。

Look into static properties and (ultimately) static classes.查看静态属性和(最终)静态类。 Maybe not the most elegant solution but great learning material!也许不是最优雅的解决方案,而是很棒的学习资料!

Edit: you can find a good tutorial here: http://www.dotnetperls.com/static编辑:你可以在这里找到一个很好的教程: http : //www.dotnetperls.com/static

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM