473,394 Members | 1,761 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,394 software developers and data experts.

Instantiating Array of Objects then accessing variables

I have a problem with trying to instantiate an array of object types from a class that I have made. I am doing this becuase I want to easily access their data members from their array all at once such as: Address[0].Zip, Address[1].Zip, Address[3].Zip, ect. My problem is that when I made an object array to hold them in, they don't show up once I use the dot operator in the Intellisense, so it makes me feel as if I am doing something wrong:


Expand|Select|Wrap|Line Numbers
  1. //object array to hold each address
  2. object[] test = new object[10];
  3.  
  4. //I know hard coding this is not the best option, but I
  5. //wanted to make sure this wasn't where I was messing up at
  6. test[0] = new Address("Oak Chase Dr", "Tucker", "Georgia", 30041);
  7. test[1] = new Address("Oak Chase Dr", "Decatur", "Georgia", 30042);
  8. test[2] = new Address("Oak Chase Dr", "Atlanta", "Georgia", 30040);
  9. test[3] = new Address("Oak Chase Dr", "Decatur", "Georgia", 30044);
  10. test[4] = new Address("Oak Chase Dr", "Tucker", "Georgia", 30084);
  11. test[5] = new Address("Oak Chase Dr", "Atlanta", "Georgia", 30040);
  12. test[6] = new Address("Oak Chase Dr", "Atlanta", "Georgia", 30040);
  13. test[7] = new Address("Oak Chase Dr", "Decatur", "Georgia", 30038);
  14. test[8] = new Address("Oak Chase Dr", "Tucker", "Georgia", 30039);
  15. test[9] = new Address("Oak Chase Dr", "Atlanta", "Georgia", 30040);
  16.  
  17. //will hold address with same Zip
  18. List<Address> Addresses = new List<Address>();
  19.  
  20.  
  21. for (int i = 0; i < address.Length ; i++)
  22. {
  23. //here's problem 1, cannot find "address[i].Zip"
  24. if (address[i].Zip == 30040)
  25. {
  26. //problem 2, 
  27. Addresses.Add(address[i]);
  28. }
  29. i++;
  30. }
  31.  
  32. public class Address
  33.     {
  34.         //properties
  35.         public string StreetName;
  36.         public string City; 
  37.         public string State;
  38.         public int Zip;
  39.  
  40.         //consructor
  41.         public Address(string StreetName, string City, string State, int Zip)
  42.         {
  43.             StreetName = "Street";
  44.             City = "City";
  45.             State = "State";
  46.             Zip = 00000;
  47.         }
  48.  
  49.         //destructor
  50.         ~Address() { }
  51.     }
  52.  
  53.  
Oct 22 '11 #1
1 1586
Rabbit
12,516 Expert Mod 8TB
Your array is called addresses not address.
Oct 23 '11 #2

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

Similar topics

3
by: Leigh Riley | last post by:
Hi, Can someone tell me if the following is possible? I have a file containing some STATIC variables, and some functions e.g. -------------------------------------------------...
1
by: Jo Schambach | last post by:
I want to build an array of entry widgets in python with Tkinter that all have similar textvariables. I was hoping that I could use an array of StringVar variables to attach to these widgets, so...
4
by: Jim Heavey | last post by:
Hello, I have created a form which I intend to use a a dialog box. It has a few controls on that form and I changed the properties of those controls to "public" with the idea that I could access...
2
by: Raphael Iloh | last post by:
Hi all, I'm having problems comparing array objects. Take a look at this: int array1 = new int{1}; int array2 = new int{1}; Console.Writeln(array1.Equals(array2)); One would expect the above...
10
by: Steve | last post by:
this code: private Array m_arrays = new Array; results in an array of 3 null Array objects. What am I missing?
2
by: active | last post by:
Because of an example I followed I've been instantiating Image objects. Now I notice that the documentation says the Image class is an abstract base class. Things seem to be working! Is the...
1
by: Nathan | last post by:
Hi, I have created a class library creating a number of forms and a few public variables. I have a project that references the .dll for this class library, and in that project I need to access...
2
by: Jurek Dabrowski | last post by:
hi all, I have a question in reference to accessing variables in another class maybe someone has dealt with before. I have some public variables declared in my main plug-in class...
4
Ispep
by: Ispep | last post by:
Hi, unfortunately having a bit of difficulty with a question from an Open University course I'm currently doing. If you could help me out in any way I'd be grafeul (though obviously it goes without...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.