473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how would you share a variable between 2 classes in VC#?

13
i'm trying to share the variable: target

This section of code:
Expand|Select|Wrap|Line Numbers
  1.  
  2.             //draw rectangles for the edges filter
  3.             if( coordinateList.CalculateEdges().Length > 0 )
  4.             {
  5.                 using( Graphics graphics = Graphics.FromImage( newImage ) )
  6.                 {
  7.                     graphics.DrawRectangles(
  8.                         new Pen( Color.Blue, 1 ),
  9.                         coordinateList.CalculateEdges());
  10.                     //code i added to display 'target'
  11.                     graphics.DrawRectangle(
  12.                         new Pen(Color.Red, 2), target);
  13.                 }
  14.             }


Is in the ImageProcessing class and this;
Expand|Select|Wrap|Line Numbers
  1.  
  2.                 if (coordinateList.Count != 0)
  3.                 {
  4.  
  5.                     int x1 = 0;
  6.                     foreach (PointOfInterest p in coordinateList)
  7.                     {
  8.                         x1 += p.XCoordinate;
  9.                     }
  10.                     double aX = x1 / coordinateList.Count;
  11.  
  12.                     int y1 = 0;
  13.                     foreach (PointOfInterest p in coordinateList)
  14.                     {
  15.  
  16.                         y1 += p.YCoordinate;
  17.  
  18.                     }
  19.  
  20.                     double aY = y1 / coordinateList.Count;
  21.  
  22.  
  23.  
  24.                     int x = (int)Math.Round(aX, 0);
  25.  
  26.                     int y = (int)Math.Round(aY, 0);
  27.  
  28.  
  29.  
  30.                     PointOfInterest target = new PointOfInterest(x, y);
  31.  
  32.                     coordinateList.Add(target);
  33.  
  34.  
  35.  
  36.                 }
  37.  
is in the CoordinateList inner-class. I could never get classes to share a variable..It’s as if I need a global variable but C# of course doesn’t use them plus it would be considered bad OOP.
Feb 3 '08 #1
1 1490
weaknessforcats
9,208 Expert Mod 8TB
Sharing variables is a big no-no.

Just write a method in class A that returns the value. Have class B call that method, fiddle with the value and then call another method in A to record the new value.
Feb 3 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: S Johnson | last post by:
>Trying to start first time using command: > C:\mysql\bin\mysqld --standalone > > Yields this error message: Can't find > messagefile'C:mysqin\share\english\errmsg.sys' aborting > > Now in...
6
by: Tony Fonager | last post by:
I am currently developing a statistics system in ASP.NET, and need to share information about the customers websites, in this application. (I have simplified my code, to make my project easier to...
8
by: Tony Fonager | last post by:
I am currently developing a statistics system in ASP.NET, and need to share information about the customers websites, in this application. (I have simplified my code, to make my project easier to...
3
by: musosdev | last post by:
Hi guys Okay, I've setup my projects to open and compile fine in VS2005 using FPSE and remote web, but it's *really* slow. So I thought I'd have a go at doing it the normal way, by loading from...
5
by: Scott Starker | last post by:
Is there anyway to do this? Every time any button is click inside class Form1, MyButtomArray.CharArray (MyButtomArray is a class) gets set (or reset) (bool). Once this is done the class TEC gets...
1
by: Mario-ITA | last post by:
Hi, sorry for the pretty question. i want to change this Connection String at RunTime namespace NeoBiblos.BiblosDataSetTableAdapters { .... public partial class ArgomentTableAdapter :...
3
by: Samuel R. Neff | last post by:
Is there any way to declare a static variable within a generic type definition and have that variable be shared across all constructed generic types? For example, how can I modify this code: ...
7
by: viettrung | last post by:
Hi, I have two classes that share a common data list (specifically, a std::vector). This data list should be accessed by the two classes only, so I think using a global variable is not a good...
6
by: Immortal Nephi | last post by:
First class is the base class. It has two data: m_Base1 and m_Base2. Second class and third class are derived classes and they are derived from first class. m_Base1 and m_Base2 are inherited into...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.