Solved

how do i create an array of objects by a function return?

Posted on 2006-11-10
3
184 Views
Last Modified: 2010-04-16
here goes experts:

i have a class lets call it myClass.

i want to create an array of myClass objects by a function return like this:

 myClass[]  l_oClass = myFunction();

myFunction looks like this:
 public myClass[] myFunction()
{
    myClass[] l_oClassArray = new myClass[10];

   // alternate code here

    return l_oClassArray;
}

where it says //alternate code here
i have tried to say
  l_oClassArray.Initialize();

or alternatively:
 for( int i=0; i++; i<10)
{ l_oClassArray[i] = new myClass(); }

neither of which stopped me from seeing "object not set to a reference" error when i tried to use the objects

any suggestions?
i have also tried passing the myClass array by ref into the function and then I get the same "not a reference" error when it comes back  even though its been initialized and used inside myFunction before control is returned.

-thanks
0
Comment
Question by:richardsimnett
[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
3 Comments
 
LVL 15

Accepted Solution

by:
ozymandias earned 500 total points
ID: 17916939
for( int i=0; i++; i<10)
{ l_oClassArray[i] = new myClass(); }


the above should work (except that you have a couple of the arguments the wrong way round)

for( int i=0; i<10; i++){
    l_oClassArray[i] = new myClass();
}

0
 

Author Comment

by:richardsimnett
ID: 17917078
>except that you have a couple of the arguments the wrong way round
its always fun without intellisense ;)

ok. so what you are saying is basically that what i am doing should work and that if i am seeing an error it must be generated elsewhere in the code.  (obviously there is alot more going on with my classes than what i posted)

let me wait and see if I get anymore interesting responses before awarding you the points.

thanks alot
0
 

Author Comment

by:richardsimnett
ID: 17917307
werd.
you get the points.

it was right all along.  there was a problem with the X|\/|L parsing that was populating the class.

i didnt believe it was right until you agreed, so your help was instrumental.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Amazon S3 .Net error 5 78
Using/Import statement in code doesn't see reference of dll just added. 3 40
ComboBox to String Not Working 5 43
How does this modal work? 3 33
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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…

734 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