How to declare an Array to send as ref

There is a DLL I use that had a Method that looks like this:

AskJobPages(ref Array Pages)

So I should declare an Array and send it as a ref. The method will fill the array with pagenumbers (int).

I tried this:

            Array pages = new int[999];
            clarity.AskJobPages(ref pages);

Open in new window


But this is not the way. I get the errormessage:
Value does not fall within the expected range.
on the second line.

Any suggestions?
omroepbrabantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Yes, that is the correct way to pass variables so they will be directly modified within the called method (since the method is defined with a ref parameter). Is it possible to see the definition of AskJobPages?
omroepbrabantAuthor Commented:
No, I don't have the source and the documentation is not program language speciffic.

I wonder if the message "Value does not fall within the expected range" indicates that the array is of the wrong length.
I don't know the length of the resulting array.
käµfm³d 👽Commented:
I wonder if the message "Value does not fall within the expected range" indicates that the array is of the wrong length.
Which is what I thought as well. I wondered if the target function was expecting a smaller array than 999.
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

omroepbrabantAuthor Commented:
I've tried a smaler array,
100, 10, even 1.
käµfm³d 👽Commented:
Out of curiosity, what is the type of the exception being raised?
fromerCommented:
You are passing the parameter as "ref"...Arrays are reference types, ***probably*** the method will create
and instance for the parameter "pages"...

try this,
Array pages = null;
clarity.AskJobPages(ref pages);

if you get the same exception, then there is a problem with the method AskJobPages...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
@fromer

"ref" parameters imply that the variable is initialized prior to the function call containing the "ref" param. "out" params are ones that can be null before being passed to a function that accepts such a parameter.
fromerCommented:
Yes you are right...
What is the purpose of passing a Reference Type as ref parameter?...function implies that, if the size of the array is not enough, i may ReConstruct it (ReAllocate, ReCreate, Grow)....
i don't think that, the exception occurs due to the size of the Array...It comes from the internal structure of the method...
fromerCommented:
The purpose of my suggestion was to learn if the method ReConstructs (ReAllocate, ReCreate, Grow) the array parameter..if you we send null as parameter, and the method does not reconstructs it, then the exception should turn to be an Access Violation exception...
omroepbrabantAuthor Commented:
Passing an empty Array worked like fromer sugested, it fills the array for me... Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.