C# Class Array basic question items

Posted on 2012-08-31
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[].
Question by:sbornstein2
    LVL 21

    Accepted Solution

    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";

    Author Closing Comment

    Ah thanks.   Thanks again appreciate your help.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    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…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now