zoukankan      html  css  js  c++  java
  • c# Foreach last (zz)

    c# Foreach last
    //z 2012-09-06 15:49:01 IS2120@CSDN.T2414191273[T14,L128,R4,V138]
    If you just need to do something with the last element (as opposed to something different with the last element then using LINQ will help here:

    Item last = Model.Results.Last();
    // do something with last
    

    If you need to so something different with the last element then you'd need something like:

    Item last = Model.Results.Last();
    foreach (Item result in Model.Results)
    {
        // do something with each item
        if (item.Equals(last))
        {
            // do something different with the last item
        }
        else
        {
            // do something different with every item but the last
        }
    }
    

    Though you'd probably need to write a custom comparer to ensure that you could tell that the item was the same as the item returned byLast().

                using (System.IO.StreamWriter writer = new System.IO.StreamWriter (@"e:\e.txt"))
                {
                    writer.Write(sb.ToString());
                }
  • 相关阅读:
    [转]ASP.NET 导出Excel 80070005错误解决备忘
    [转]整理.net程序集加载方法
    Jquery示例
    WQL测试工具
    asp.net 2.0的事务问题
    <转>xPath教程
    .NET代码编写规范
    sqlserver2005 技巧
    MySQL(5.0)导出导入
    Castle ActiveRecord 笔记
  • 原文地址:https://www.cnblogs.com/IS2120/p/6745835.html
Copyright © 2011-2022 走看看