我的 C# 2.0 中有以下情况。
有一些 VbScript 代码:
For i = 0 to UBound(components) - 1
If i = UBound(Components) - 1 Then
WriteOut "<div class=""clearBoth""></div>"
End If
Next
下面我正在尝试用C#编写,请建议在c#中为“If i = UBound(Components) - 1 Then”编写什么条件。
List<tc.ComponentPresentation> cmp = new List<tc.ComponentPresentation>();
foreach (tc.ComponentPresentation cm in cmp)
{
//Here I want to right one condition that
if(this is the last object in "cmp" list)
{
////do something
}
}
请推荐!!
最佳答案
if (cmp[cmp.Count - 1] == cm)
这应该有效。
关于c# - 如何在 C# 2.0 中从 List<> 获取最后一个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7955021/