0

from my function below, I am returning an array. In C# how would I consume that array?

 public Array arrayFucntion()
 {
// do something

 foreach (var Objs in items)
            {



                list.Add(Objs.value1);


            }

            string[] myArray = list.ToArray();
            MessageBox.Show(myArray.ToString());
            return myArray;
}

Now how would I use it in a function like below

void consumeFunction()
        {

            var x = arrayFucntion();

       // what do do to see values of the array


        }

4 Answers 4

3

Return a string[], then you can do the for loop through the string array.

public string[]arrayFucntion()

void consumeFunction()
{
  var x = arrayFucntion();
  for (int i=0; i<x.Lenght; i++)
  {       
    x[i]...
  }
}
Sign up to request clarification or add additional context in comments.

Comments

2

Make the return type string[] instead of Array.

Comments

0

You can iterate through the members:

foreach (string sArrayMember in x)
{
   // Do something with s
}

You can also access any of the properties or members listed in the MSDN documentation, including Copy, Find, and Sort.

Comments

0

x is now an array object...

you can do foreach on it, or use linq.....or using direct addressing x[0]

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.