Implementing IList

Posted on 2004-11-08
Last Modified: 2008-02-01

when looking at the following snippet of code, how is the following possible?

public class CustomerInfoCollection : IList
   private ArrayList m_alCustomerInfo;
   //constructor yada yada yada

   public int Add(object value)
      if (value is CustomerInfo)
         return m_alCustomerInfo.Add(value);
         //do somehting else here

My question is:  the Add function returns an integer.  However, the body returns an ArrayList.  Wouldn't that throw some sort of an Exception?

thanks from a C# newbie....

Question by:brdrok
    LVL 14

    Expert Comment

    What do you mean, "the body returns an ArrayList"? The int returned by the add function is the index inside the ArrayList of the newly added element.
    LVL 9

    Accepted Solution

    Keep in mind the following.....

    The add function as you said, does not return an ArrayList, but the result of the add method called to that Arraylist.

    As you said....

             return m_alCustomerInfo.Add(value);

    So both are returning an int, and that's why it does not throw any exception

    Hope this helps


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    Title # Comments Views Activity mvc 2 30
    WPF Update a user control embedded into my window 3 21
    Query datatable in LINQ 6 24
    C# - SOLID Question 6 35
    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    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…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    779 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

    21 Experts available now in Live!

    Get 1:1 Help Now