Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用从方法返回的数组_C# - Fatal编程技术网

C# 使用从方法返回的数组

C# 使用从方法返回的数组,c#,C#,从下面的函数中,我返回一个数组。在C#中,我将如何使用该数组 public Array arrayFucntion() { // do something foreach (var Objs in items) { list.Add(Objs.value1); } string[] myArray = list.ToArray(); MessageB

从下面的函数中,我返回一个数组。在C#中,我将如何使用该数组

 public Array arrayFucntion()
 {
// do something

 foreach (var Objs in items)
            {



                list.Add(Objs.value1);


            }

            string[] myArray = list.ToArray();
            MessageBox.Show(myArray.ToString());
            return myArray;
}
现在我如何在下面这样的函数中使用它

void consumeFunction()
        {

            var x = arrayFucntion();

       // what do do to see values of the array


        }

返回字符串[],然后可以通过字符串数组执行for循环

public string[]arrayFucntion()

void consumeFunction()
{
  var x = arrayFucntion();
  for (int i=0; i<x.Lenght; i++)
  {       
    x[i]...
  }
}
public string[]arrayfuntion()
void函数()
{
var x=arrayfuntion();

for(int i=0;i返回字符串[],然后可以通过字符串数组执行for循环

public string[]arrayFucntion()

void consumeFunction()
{
  var x = arrayFucntion();
  for (int i=0; i<x.Lenght; i++)
  {       
    x[i]...
  }
}
public string[]arrayfuntion()
void函数()
{
var x=arrayfuntion();

对于(int i=0;i您可以遍历成员:

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

您还可以访问中列出的任何属性或成员,包括复制、查找和排序。

您可以遍历这些成员:

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

您还可以访问中列出的任何属性或成员,包括复制、查找和排序。

将返回类型设置为
string[]
而不是
Array

将返回类型设置为
string[]
而不是
Array

x
现在是
数组对象


您可以在它上面执行foreach
foreach
,或者使用
linq
…或者使用直接寻址
x[0]
x
现在是一个
数组对象

您可以在上面执行foreach
foreach
,或者使用
linq
…或者使用直接寻址
x[0]