C# 如何为列表传递参数?
在这里,我将列表作为参数传递,但不知道如何调用字段来与其他字段进行比较和检查 //检查此代码C# 如何为列表传递参数?,c#,list,C#,List,在这里,我将列表作为参数传递,但不知道如何调用字段来与其他字段进行比较和检查 //检查此代码 public RankModels created(List<collection_master> col) { if (col == null) return null; ; return new RankModels() { CustomerID = col.CustomerID,--
public RankModels created(List<collection_master> col)
{
if (col == null)
return null; ;
return new RankModels()
{
CustomerID = col.CustomerID,--error
AmountRecevied = col.AmountRecevied,--error
Date_Time = col.Date_Time,
Area = col.Area,
AgentID = col.AgentID,
Money_Receipt_No = col.Money_Receipt_No,
Payment_Mode = col.Payment_Mode,
Money_Receipt_Photo = col.Money_Receipt_Photo
};
}
创建的公共RANKMODEL(列表列)
{
if(col==null)
返回null;
返回新的RankModels()
{
CustomerID=col.CustomerID,--错误
amunreceived=列amunreceived,--错误
日期时间=列日期时间,
面积=柱面积,
AgentID=col.AgentID,
货币收据编号=列货币收据编号,
付款方式=列付款方式,
货币收据照片=col.Money\u Receipt\u Photo
};
}
col
是集合\u master
对象的列表。因此,您不能使用这样的col.CustomerID
。您必须使用索引从集合中获取元素,然后读取其属性。比如说,
col[0].CustomerID
将为您提供列表中第一个对象的
CustomerID
属性值。您的代码错误col
是一个列表,您无法通过该列表访问collection\u master
的属性
使用类似于:
CustomerID = col[0].CustomerID
并且将起作用您可以这样调用该方法
RankModels rankModel= created(col[0])
你不知道
col
是一个列表吗?是的,不知道怎么做,非常简单,学习C#并更多地使用列表。列表是一个包含大量对象的集合。每个对象在列表中都有一个位置。在询问问题之前,您应该先了解列表qus@sandeep不客气!是的,有一点。虽然,我建议你发布另一个问题,为了吸引对web api有丰富经验的用户的注意,你可以得到你想要的。我在mysql中使用了wriiten查询,我想在EF下面的链接中更改它,他们关闭了我的问题y,我不知道那是什么。答案是什么?@sandeep我稍后会查出来,然后再给你回复。