[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Implementing IList

Posted on 2004-11-08
2
Medium Priority
?
465 Views
Last Modified: 2008-02-01
Hello,

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);
       }
      else
     {
         //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....

0
Comment
Question by:brdrok
2 Comments
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12528159
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.
0
 
LVL 9

Accepted Solution

by:
tinchos earned 200 total points
ID: 12528750
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

Tincho
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Loops Section Overview
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

834 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