473,809 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Instantiating Array of Objects then accessing variables

1 New Member
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 1596
Rabbit
12,516 Recognized Expert Moderator MVP
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
15265
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. ------------------------------------------------- $ARCHIVE_INPUT_FILES = false; $ARCHIVE_OUTPUT_FILES = false; $ARCHIVE_CONFIG_FILES = false; $HTML_BODY_BACKGROUND = "gfx/gradient.gif";
1
10482
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 that I can loop through the widget creation. But my simple minded approach failed: for i in range(32): self.dllAdjust = StringVar() self.dllAdjust.set('000') gives me the following error:
4
12108
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 those controls from the "calling form", but I am unable to access/see those controls. Why? Here are portions of my code Here I am substantiating the new form and trying to set values for the controls on that form...
2
2044
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 expression to return true as both arrays are identically the same but it keeps returning false. Any info on how to solve this problem will be appreciated.
10
12233
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
1250
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 documentation wrong (it also says abstract classes cannot be instantiated)? Should I be using Bitmap instead? Is there a difference between Abstract class and Abstract base class?
1
1221
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 those public variables. For instance, the main app calls a form in the referenced library, that form changes the value of PublicVar1 and then closes. The main app now needs to know the value of PublicVar1.
2
2358
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 CCommandMeshToSrf, eg: BOOL m_bHaveAnswer; I want to set this variable from within a dialog class which is defined in separate .h and .cpp files of course. How would one access this varibale from a method defined in my CTestModelessDialog class ?
4
3833
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 saying I'm not asking you to solve the question - that won't help come exam time :(). Anyway I have a CSV delimited file in the following format; STRING,INT STRING,INT,INT,INT,INT,INT STRING,INT,INT,INT,INT,INT STRING,INT,INT,INT,INT,INT ...
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10640
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10387
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10120
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.