[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C# Class Array basic question items

Posted on 2012-08-31
2
Medium Priority
?
373 Views
Last Modified: 2012-08-31
Hello all,

I have an API that has a class as something I need to pass to it one of it's attributes.  I am aweful with arrays.  So what it has is this:

It has a class named CustomerDetail with attributes of course CustID, CustName etc.  Then the attribute I need to pass into the API method is called CustomerDetails which is expecting it looks like CustomerDetail[] so it accepts multiple.   So what I did was this and intellisense seemed to work:

 CustomerDetail[] prs = new CustomerDetail[1];
            prs[0].CustID = 2;
            prs[0].CustName = "Cust1";

I get an object not set to an instance of an object error on CustID.  What am I doing wrong.  The attribute CustomerDetails when I hover over it shows CustomerDetail[].
0
Comment
Question by:sbornstein2
2 Comments
 
LVL 21

Accepted Solution

by:
mastoo earned 600 total points
ID: 38354559
You created the array to hold CustomerDetail objects, but you didn't create the objects themselves (or in this case the one object).

CustomerDetail[] prs = new CustomerDetail[1];
prs[0] = new CustomerDetail();
            prs[0].CustID = 2;
            prs[0].CustName = "Cust1";
0
 

Author Closing Comment

by:sbornstein2
ID: 38354579
Ah thanks.   Thanks again appreciate your help.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question