Solved

Passing class derived from ArrayList

Posted on 2004-10-20
2
219 Views
Last Modified: 2010-05-18
my class "List", is derived from "ArrayList".

I have a function, "foo" that accepts an "ArrayList" as a parameter.


foo(ref ArrayList al)
{
...
}


I want to pass an object of type "List" to foo:


foo(ref List )


but when i cast it, it says it needs to be an lvalue, because its a ref.


What should i be doing?

TIA.
0
Comment
Question by:dave_p_r_b
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
gav_jackson earned 125 total points
ID: 12356253
you just pass the list object directly into foo (it will be a reference type anyway as it is an arraylist)

foo(List myList)
{
  //myList does not need to be cast as its already a "List" object
}


or am i totally missing the point?
0
 

Author Comment

by:dave_p_r_b
ID: 12356286
No, youve hit the point spot on.

Thanks for your help!

For anyone else, I found an article on msdn that explains  "Passing Reference types by value" .

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfPassingMethodParameters.asp
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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