如何使用同一名称空间中另一个类的变量的值? [英] How could I use the value of a variable from another class in the same namespace?

查看:56
本文介绍了如何使用同一名称空间中另一个类的变量的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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...


这篇关于如何使用同一名称空间中另一个类的变量的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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