我有类似...的 list
List[0] = "Banana"
List[1] = "Apple"
List[2] = "Orange"
我想使用以下代码将其生成为
"My-Banana,My-Apple,My-Orange"
:string AnyName = string.Join(",", Prefix + List));
但是没有得到预期的输出,如何在每个项目之前添加 My?
最佳答案
您是否正在寻找类似this Example的内容:
listInput[0] = "Apple";
listInput[1] = "Banana";
listInput[2] = "Orange";
string Prefix = "My-";
string strOutput = string.Join(",", listInput.Select(x=> Prefix + x));
Console.WriteLine(strOutput);
然后您将得到输出为
My-Apple,My-Banana,My-Orange
关于c# - 字符串列表,以逗号分隔,并在列表的每个项目中添加前缀字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47466770/