0

In a function I am taking an array and resizing it. I made the function an array return type and it does what it is supposed to do. The problem I am having is figuring out how to use the returned array in my program. hiLow is a function that takes the array and changes the value, the for loop only still shows the old array. How do I get creature(the name of my array) to only display the new values?

        hiLow(creature);
        for (int i = 0; i < 2; i++)
        {
            Console.WriteLine(creature[i].creatureInfo());
        }
2
  • 1
    Please post the code for hiLow Commented Feb 14, 2012 at 20:03
  • Elaborate your question with some additional example code. What do you mean "how to use the returned array in my program?" is certainly uncleared. Looking like a homeworky question. Commented Feb 14, 2012 at 20:07

2 Answers 2

3

Return crature from your method.

creature = hiLow(creature);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it turned out to be something very different, but the error that popped up after I put the code in helped me figure it out.
1

Without knowing exactly what is going on without seeing your code, one thing you will want to do is pass the array by reference into your hiLow method. This will modify the array that is being passed in and you should be able to see the new size of your array in the loop.

 hiLow(ref creature);
 for (int i = 0; i < 2; i++)
 {
     Console.WriteLine(creature[i].creatureInfo());
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.