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());
                }
  • 相关阅读:
    简单的sql注入3
    简单的sql注入2
    简单的sql注入1
    python安装request及更新pip
    kali linux上安装ssh
    看起来有点难
    猫抓老鼠
    头有点大
    貌似有点难
    这个看起来有点简单!
  • 原文地址:https://www.cnblogs.com/IS2120/p/6745835.html
Copyright © 2011-2022 走看看