c# - 在 C# 中使用其他数组的内容创建新数组

标签 c# arrays

我想知道从其他数组的内容创建新数组的最有效方法。

我有几个类型的字符串数组:

public readonly string[] Taiwan = { "TW", "TWO" };
public readonly string[] Vietnam = { "HM", "HN", "HNO" };
public readonly string[] Korea = { "KQ", "KS" };
public readonly string[] China = { "SS", "SZ" };
public readonly string[] Japan = { "T", "OS", "NG", "FU", "SP", "Q", "OJ", "JNX", "IXJ", "KAB", "JA", "JPx" };

现在可以用与此类似的方式创建一个新的字符串数组吗?

public readonly string[] ASIA = { Taiwan, Vietnam, Korea, China, Japan};

这将包含其他数组中包含的所有字符串。

最佳答案

string[] ASIA = new []{ Taiwan, Vietnam, Korea, China, Japan}
                      .SelectMany(s => s)  // not entirely sure what these abbreviations are...
                      .ToArray();

关于c# - 在 C# 中使用其他数组的内容创建新数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17753670/

相关文章:

c# - 自动夹具 + NSubstitute : Freezing a mock?

c# - webapp 的 `InSingletonScope` 究竟有多长?

c# - "Reverse"WCF 服务(从客户端定义构建服务器)

C++使用标准输入的大小初始化数组

arrays - 如何在 scala 中的二维数组上使用 contains 方法

c# - 具有超过 65535^2 个元素的二维数组 --> 数组维度超出支持范围

c# - 动态显示 Razor ValidationMessageFor

c# - 我如何跳转到 Resharper 中的下一个引用?

c - C 中的多维数组

javascript - 具有用户输入的数组上的 NaN