Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
QueryAnalysis.cs:
C#
namespace DiseaseQuery
{
    public partial class QueryAnalysis : Form
    {
       public static int i = 0;

       public QueryAnalysis()
       {
         InitializeComponent();
       }

    }
}


MySimpleQuery.cs:
C#
namespace DiseaseQuery
{
    public partial class MySimpleQuery : Form
    {
        public MySimpleQuery()
        {
            InitializeComponent();

            int j;
        }
   }
}


How could I pass the value of "i" to "j"?
Posted
Updated 3-Mar-11 15:43pm
v2

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
 
Share this answer
 
Comments
Scarlettlee 3-Mar-11 21:53pm    
Thank you very much for your suggestion! I will think about it.
Sergey Alexandrovich Kryukov 3-Mar-11 22:16pm    
Thank you for understanding.
--SA
C#
j = QueryAnalysis.i;
 
Share this answer
 
Comments
CS2011 3-Mar-11 13:49pm    
John..will it work....i don't see int i as public member ?
#realJSOP 4-Mar-11 5:50am    
It says "public static" in the code he posted.
Scarlettlee 3-Mar-11 21:47pm    
John Simmons & chanakya1984, thank you both for your great help!
I have solved the problem by adding "public" to "i",and then use j = QueryAnalysis.i;
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...
 
Share this answer
 
v3
Comments
Scarlettlee 3-Mar-11 21:51pm    
To reach my goal, the "public" and "static" are both needed as I have tested it to draw this conclusion.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900