如何删除添加到列表中的最后一个元素?
我在其中我加入列表fields.Now同时加入我要检查的条件,如果条件满足,然后我需要从列表中删除添加的最后一行C#的List。
下面是我的示例code ..
I have a List in c# in which i am adding list fields.Now while adding i have to check condition,if the condition satisfies then i need to remove the last row added from the list. Here is my sample code..
List<> rows = new List<>();
foreach (User user in users)
{
try
{
Row row = new Row();
row.cell = new string[11];
row.cell[1] = user."";
row.cell[0] = user."";
row.cell[2] = user."";
rows.Add(row);
if (row.cell[0].Equals("Something"))
{
//here i have to write code to remove last row from the list
//row means all the last three fields
}
}
所以我的问题是如何从名单在C#中删除最后一行。
请帮我。
So my question is how to remove last row from list in c#. Please help me.
哦,亲爱的。那岂不是更有意义不添加行的第一个地方?
Oh dear. Wouldn't it make more sense not to add the row in the first place?
Row row = new Row();
//...
if (!row.cell[0].Equals("Something"))
{
rows.Add(row);
}
TBH,我想进一步通过测试东西
对用户走了一步。
,和甚至没有实例化行
除非条件得到满足,但看到用户。
将无法编译,我想留,作为一个读者练习。
TBH, I'd go a step further by testing "Something"
against user.""
, and not even instantiating a Row
unless the condition is satisfied, but seeing as user.""
won't compile, I'll leave that as an exercise for the reader.