C# Class Array basic question items

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[].
sbornstein2Asked:
Who is Participating?
 
mastooCommented:
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
 
sbornstein2Author Commented:
Ah thanks.   Thanks again appreciate your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.