Alex Rivera | Logout

Declaring and Using Global Arrays c#

Asked 2012-01-04T21:36:52.087
8

I couldn't find any information pertaining to this question. I am trying to create a global array in C# so that I can input information into it at different points in my code and then call the information back at a later time to display it. For example, I want to take the following information and put it into the array:

string auctionID;
string itemName;
string itemID;
string bid;
string buyout;
string quantity;

I then want to be able to call that array with a for loop, or something similar, so that I can display that information at a later time. Now, one little thing that I forgot to mention is that I am probably going to need either an array of arrays or a multi-dimensional array. The reason for this is because I am going to have lots of different auctions and the data about each auction (hence the variables above) and I want to display that information at the very end of the program. Thank you for your time!

Update 1

So, I think I am not making myself clear because I am getting confused, but that could also be because I'm a little frustrated at the moment with this program. I want to be able to create a global array and then get & set the information stored in that array with different functions within my program as different functions will be modifying different parts of that array. Also, I wouldn't mind using caching, if I understood how that worked or even had a link to read about it. One last thing to add, I am doing this on the Windows Phone 7, so I am limited on which libraries and system calls I can use.

Update 2

I am quite a bit rusty on OOP, so I am going to go read up more on it (thanks to dealing a ton with HTML and not really having a chance to do real programming). Thanks for everyone's suggestions. I will probably post back on this topic if I can't figure out something further. Cheers!

Edit
Report

2 Answers

2

Well, aside from the fact that you likely have a structural problem if you're storing stuff globally.

You can use a static property for this.

 public class MyVariables
 {
     private static string[] _MyStuff
     public static string[] MyStuff
     {
           return _MyStuff;
     }
 }

Then access it like this:

MyVariables.MyStuff[0]
answered 2012-01-04T21:40:20.197
1

I think Dictionary<string, string> will be more suitable... You can loop through it and access a specific item. And also pass it to your methods.

answered 2012-01-04T21:43:01.440

Your Answer