本文介绍了如何将集合转换为字符串变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个LINQ集合。我想从集合中获取所有值并设置为字符串变量。
我的方案是 - >
Foreach(SalesPlan.Riders中的var riderId)
{
string str = 101,102,103; //这是riderId来自salePlan.riders
//这个str将从集合中填充,var riderId
}
Hi,
I have a LINQ collection.I want to take all values from collection and set into string variable.
My scenario is-->
Foreach(var riderId in SalesPlan.Riders)
{
string str= 101,102,103; //This is riderId coming from salePlan.riders
// This str will fill from collection, var riderId
}
推荐答案
Foreach(var riderId in SalesPlan.Riders)
{
string str += riderId + ","; //This is riderId coming from salePlan.riders
// This str will fill from collection, var riderId
}
str = str.substring(0, riderid.Length-1);
如果需要,可以在字符串值之间放置逗号或任何其他分隔符。
You can put in a comma or any other separator between the string values if you want to.
StringBuilder builder = new StringBuilder();
foreach(var riderId in SalesPlan.Riders)
{
builder.Append(riderId);
//bulider.AppendLine(riderId.ToStirng());
}
console.writeline(bulider);
我认为这有助于
I think this helps
这篇关于如何将集合转换为字符串变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!