如何使用同一名称空间中另一个类的变量的值?

如何使用同一名称空间中另一个类的变量的值?

问题描述:

QueryAnalysis.cs:

QueryAnalysis.cs:

namespace DiseaseQuery
{
    public partial class QueryAnalysis : Form
    {
       public static int i = 0;

       public QueryAnalysis()
       {
         InitializeComponent();
       }

    }
}



MySimpleQuery.cs:



MySimpleQuery.cs:

namespace DiseaseQuery
{
    public partial class MySimpleQuery : Form
    {
        public MySimpleQuery()
        {
            InitializeComponent();

            int j;
        }
   }
}





How could I pass the value of "i" to "j"?

如果不断问这样的问题,您将学不到很多东西. > 您需要先做家庭作业,并阅读足够的语言和编程知识,并做足够的简单练习.然后,您将可以提出对您更有用的问题.

请参阅我的学习建议:我有问题与我的程序.请帮忙! [ http: //norvig.com/21-days.html [ ^ ].

-SA
You won''t learn much if you keep asking questions like that.
You need do do homework first, and read enough in the language and programming, do enough simple exercises. Then you will be able to ask questions which will be much more useful for you.

Please see my learning suggestions: I have a problem with my program. Please help![^].

This is the first to read: Teach Yourself Programming in Ten Years: http://norvig.com/21-days.html[^].

—SA


j = QueryAnalysis.i;


您将变量"i"声明为静态,因此无需使用QueryAnalysis实例即可访问它.
只需使用语法[ClassName] [静态,公共属性/变量名称],就像John Simmons向您展示的那样.
如果您不想访问静态成员,则需要QueryAnalysis的实例...
You declared you variable "i" as static, so you can access it without an instance of QueryAnalysis.
Just use the syntax [ClassName][static,public property/variable name] like John Simmons showed you.
If you don''t want to access a static member, you need an instance of QueryAnalysis...