文章内容

2017/10/7 15:24:30,作 者: 黄兵

string array

c# string array的用法:

class Program
{
    static void Main()
    {
        // String arrays with 3 elements.
        string[] arr1 = new string[] { "one", "two", "three" };
        string[] arr2 = { "one", "two", "three" };
        var arr3 = new string[] { "one", "two", "three" };

        string[] arr4 = new string[3];
        arr4[0] = "one";
        arr4[1] = "two";
        arr4[2] = "three";
    }
}

c# string array的运算:

using System;

class Program
{
    static void Main()
    {
        // Three-element array.
        int[] array = { -5, -6, -7 };
        // Pass array to Method.
        Console.WriteLine(Method(array));
    }

    /// <summary>
    /// Receive array parameter.
    /// </summary>
    static int Method(int[] array)
    {
        return array[0] * 2;
    }
}
Output

-10

参考资料:c# array example.

分享到:

发表评论

评论列表