c# - C#中的字符串数组

标签 c# arrays

我在字符串数组中插入字符串元素时遇到问题...例如,我有三个赋值行:

a = b
b = c
c = e

然后我想把这六个变量插入到string[]变量中。

我使用了下面的代码,但是这段代码只插入了最后一个赋值变量 (c, e)。

for (int i = 0; i < S; i++)  // S = 3 number of assignment line
{
    variables = assigmnent_lines[i].Split('=');
}

最佳答案

List<string> this_is_a_list_of_strings = new List<string>();
foreach (string line in assignment_lines)
{
    this_is_a_list_of_strings.AddRange(line.Split('='));
}
string[] strArray = this_is_a_list_of_strings.ToArray();

关于c# - C#中的字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8620629/

相关文章:

C++:我可以将子对象放入父对象数组中吗?

将值从一个数组复制到另一个数组

c# - 如何使用 System.Security.Cryptography 生成随机 int 值

javascript - 如何通过这些对象的属性访问数组中的对象?

c# - Environment.GetEnvironmentVariable ("windir") 奇怪的行为

c# - SQL 查询抛出错误 C#

javascript - 循环一个数组来替换 DIV 类

java - 在for循环java中为json对象添加值

c# - dotnet-run 命令未按预期工作

C# Outlook Mailitem ContextMenu 和 Ribbon 不能一起工作(只能单独使用)