CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Jan 2008
    Posts
    10

    how would you share a variable between 2 classes?

    i'm trying to share the variable: target

    This section of code:
    Code:
                //draw rectangles for the edges filter
                if( coordinateList.CalculateEdges().Length > 0 )
                {
                    using( Graphics graphics = Graphics.FromImage( newImage ) )
                    {
                        graphics.DrawRectangles(
                            new Pen( Color.Blue, 1 ),
                            coordinateList.CalculateEdges());
                        //code i added to display 'target'
                        graphics.DrawRectangle(
                            new Pen(Color.Red, 2), target);
                    }
                }

    Is in the ImageProcessing class and this;
    Code:
                    if (coordinateList.Count != 0)
                    {
     
                        int x1 = 0;
                        foreach (PointOfInterest p in coordinateList)
                        {
                            x1 += p.XCoordinate;
                        }
                        double aX = x1 / coordinateList.Count;
                        
                        int y1 = 0;
                        foreach (PointOfInterest p in coordinateList)
                        {
    
                            y1 += p.YCoordinate;
    
                        }
    
                        double aY = y1 / coordinateList.Count;
    
                        int x = (int)Math.Round(aX, 0);
    
                        int y = (int)Math.Round(aY, 0);
                        PointOfInterest target = new PointOfInterest(x, y);
    
                        coordinateList.Add(target);
    
                    }
    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.
    Last edited by David24; February 3rd, 2008 at 03:48 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured