我有串称为“gtinWithId”的列表,并且看起来像这个新的列表:添加分割字符串性质
1:043289235053
2:842372362912
3:672348234722
然后,我有这个类:
public class Product
{
public string Id { get; set; }
public string ProductName { get; set; }
}
然后我有这个循环来分割我的字符串列表,我的目标是将“:”之前的部分用作Id。
var listOfProducts = new List<Product>();
foreach (var gtin in gtinWithId)
{
string[] wholeString = gtin.Split(':');
string idPart = wholeString[0];
string gtinPart = wholeString[1];
//TODO
// I really don't know what to do here to assign each idPart and each gtinPart to
// the Id-property and the ProductName.propery in my new list
}
然后我想要做的就是填充我的“listOfProducts”每“串idPart”,每“串gtinPart”设定为“listOfProducts”性的判定Id和产品名称的列表。
所以我们的目标是有一个“listOfProducts”,看起来是这样的:
Id = 1 , ProductName = 043289235053
Id = 2 , ProductName = 842372362912
Id = 3 , ProductName = 672348234722
它是什么,你不明白吗?请澄清并显示您尝试解决您的问题。 – Silvermind
我很难相信你在没有先学习如何为一个对象的属性赋值的情况下编写这段代码。 – Groo
@格罗我很抱歉,但我不知道如何在每个创建的字符串中对每个创建的字符串进行排序,以便将其添加到我的新列表中。产品 – user3228992