Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用common.cs传输和存储变量_C# - Fatal编程技术网

C# 如何使用common.cs传输和存储变量

C# 如何使用common.cs传输和存储变量,c#,C#,我使用了一个common.cs文件来存储一个表单中的变量。但是,我遇到的问题是以另一种形式引用此值。目前我使用: CommonVariables comvar = new CommonVariables Comvar.Poem = textbox1.text 它存储了值,我理解这一点,但我也理解,如果我在另一个表单上再次使用代码,比如: FormEncryption Encrypt = new FormEncryption CommonVariables comvar = new Com

我使用了一个common.cs文件来存储一个表单中的变量。但是,我遇到的问题是以另一种形式引用此值。目前我使用:

CommonVariables comvar = new CommonVariables


Comvar.Poem = textbox1.text
它存储了值,我理解这一点,但我也理解,如果我在另一个表单上再次使用代码,比如:

FormEncryption Encrypt = new FormEncryption

CommonVariables comvar = new CommonVariables
textbox19.text = Encrypt.Poem
它不是引用我存储的值,而是引用一个完全唯一的值。如何使用存储的值而不是新值

任何帮助都会很好CommonVariables comvar=newcommonvariables可能是一个全局静态变量,比如在
Program.cs
(或项目中合适的任何内容)中。 (顺便说一下,您的代码示例不太正确,所以将来从代码中复制以确保没有用户错误会导致混淆)是很好的。

HI,(首先,最好从架构上考虑“最好的方法”,但现在……)