Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 135,915 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,591 people online right now. Registration is fast and FREE... Join Now!




Why isn't my public ArrayList available to other modules?

 
Reply to this topicStart new topic

Why isn't my public ArrayList available to other modules?

Pithecanthropus
16 May, 2008 - 08:51 PM
Post #1

New D.I.C Head
*

Joined: 13 May, 2008
Posts: 9

namespace RocketDyneVegetable
{


public partial class InheritedVegetableForm : RocketDyneVegetable.BaseVegetableForm
{
LineItem li;


public ArrayList LineItems = new ArrayList();
....

I currently have a public ArrayList defined in a Windows Forms class file. However, although the ArrayList is public, it's not showing up as available anywhere else in the solution. Why is this, or is there a way to work around it?

Please help out a new bee.

This post has been edited by Pithecanthropus: 16 May, 2008 - 08:53 PM
User is offlineProfile CardPM
+Quote Post

Pithecanthropus
RE: Why Isn't My Public ArrayList Available To Other Modules?
16 May, 2008 - 09:38 PM
Post #2

New D.I.C Head
*

Joined: 13 May, 2008
Posts: 9

I've also tried setting up a static class in the project that contains the ArrayList, since I only need to use one at a time. But that doesn't work either. What am I doing wrong?

The static class itself is Intellisensed elsewhere in the project, but the only attributes I can select it are .Equals and .ReferenceEquals.

I need to have a popup form containing a DataViewGrid that I want to populate from LineItems, but there seems to be no way to access it except from within the module that created it.





(Static class definition)
...

using System.Collections;

namespace RocketDyneVegetable
{

static class LineItemsCollection
{

static ArrayList LineItems = new ArrayList();
}
}

This post has been edited by Pithecanthropus: 16 May, 2008 - 09:39 PM
User is offlineProfile CardPM
+Quote Post

Pithecanthropus
RE: Why Isn't My Public ArrayList Available To Other Modules?
16 May, 2008 - 09:47 PM
Post #3

New D.I.C Head
*

Joined: 13 May, 2008
Posts: 9


OK, I finally got this straight. By adding the 'public' access modifier to the arraylist definition, it's being recognized properly now.

So now the static class looks like this.
CODE

{

    static class LineItemsCollection
    {

        public static ArrayList LineItems = new ArrayList();
    }
}


For some reason I thought I'd tried that already and it hadn't compiled.



User is offlineProfile CardPM
+Quote Post

eclipsed4utoo
RE: Why Isn't My Public ArrayList Available To Other Modules?
17 May, 2008 - 09:51 AM
Post #4

D.I.C Regular
Group Icon

Joined: 21 Mar, 2008
Posts: 349



Thanked: 19 times
Dream Kudos: 25
My Contributions
here is the more "normal" way of doing what you want.

C#

static class LineItemsCollection
{
private ArrayList m_listItems = new ArrayList();

public ArrayList ListItems
{
get { return m_listItems; }
set { m_listItems = value; }
}
}


and to access/set the data from outside the class:

C#

ArrayList arrList = new ArrayList();

LineItemsCollection lineItemCollection = new LineItemsCollection();
lineItemCollection.ListItems = arrList;

User is online!Profile CardPM
+Quote Post

Pithecanthropus
RE: Why Isn't My Public ArrayList Available To Other Modules?
17 May, 2008 - 02:28 PM
Post #5

New D.I.C Head
*

Joined: 13 May, 2008
Posts: 9

[quote name='eclipsed4utoo' date='17 May, 2008 - 10:51 AM' post='356908']
here is the more "normal" way of doing what you want.

C#

static class LineItemsCollection
{
private ArrayList m_listItems = new ArrayList();

public ArrayList ListItems
{
get { return m_listItems; }
set { m_listItems = value; }
}
}


Does this compile for you? When I do it in Visual Studio, I get an error message that I can't declare instances in a static class. It does compile if I declare the ArrayList and its property as static.

User is offlineProfile CardPM
+Quote Post

eclipsed4utoo
RE: Why Isn't My Public ArrayList Available To Other Modules?
18 May, 2008 - 06:31 AM
Post #6

D.I.C Regular
Group Icon

Joined: 21 Mar, 2008
Posts: 349



Thanked: 19 times
Dream Kudos: 25
My Contributions
Sorry, try this:

C#

public class LineItemsCollection
{
private ArrayList m_listItems = new ArrayList();

public ArrayList ListItems
{
get { return m_listItems; }
set { m_listItems = value; }
}
}


This post has been edited by eclipsed4utoo: 18 May, 2008 - 06:31 AM
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 07:58AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month