By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,764 Members | 1,436 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,764 IT Pros & Developers. It's quick & easy.

Global Variables

P: n/a
Hi All,

I am trying the follow the following MSDN tutorial:

Walkthrough: Authoring a Simple Multithreaded Component with Visual C#
(ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxmclicc/html/7bc03b7b-d680-499b-8179-5f414b2d650c.htm)

The tutorial says:

To create the Calculator component
From the Project menu, select Add Component.

Name the component Calculator.

To add public variables to the Calculator component
Open the Code Editor for Calculator.

Add statements to create public variables that you will use to pass
values from frmCalculations to each thread.

The variable varTotalCalculations will keep a running total of the total
number of calculations performed by the component, and the other
variables will receive values from the form.

Copy Code
public int varAddTwo;
public int varFact1;
public int varFact2;
public int varLoopValue;
public double varTotalCalculations = 0;

I am lost here, where do I create public variables within my component?
The source to my component currently looks as follows:

using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace Calculations
{
public partial class Calculator : Component
{
public Calculator()
{
InitializeComponent();
}

public Calculator(IContainer container)
{
container.Add(this);

InitializeComponent();
}
}
}

Thanks for any help you can offer.
Kind regards.
Mar 28 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

I assume this is VS 2005, since I couldn't locate the MSDN article in
my locally installed help.

Public variables are those variables which are accessible even outside
the class. In this case, you need variables that are not within any
method, but still within the class.

So, the place to declare them can be anywhere you want, within the
class, except within any method. Although, the generally accepted place
to declare them is right after your "Designer generated code" ends.

This would mean that you can copy and paste the list of variables right
after the ending bracket of the public Calculator(IContainer container)
method.

In other words :
-----------------------

:
public partial class Calculator : Component
{
:
public Calculator(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public int varAddTwo;
public int varFact1;
public int varFact2;
public int varLoopValue;
public double varTotalCalculations = 0;

:
:
// You can add additional methods and functions below this...

} // end class
} // end namespace

Regards,

Cerebrus.

Mar 28 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.