linq語法

  • 1445
  • 0
  • 2010-12-15

摘要:linq語法


List<int> lstMID = (from c in MAPs select c.Mid).Distinct().ToList();

取得全部編號


	plst = plst.OrderBy(r => r.LeagueIndex).ThenBy(r => r.GameIndex).ToList();

排序

 


	var gDGames = (from c in lstrtn group c by c.PlayTime.ToString("yyyy-MM-dd"));
 foreach (var gDGame in gDGames)
{

}

分組 

如果是+數字、他會『加』起來、可能會得到一樣的數字、陷阱!!


	private Action Dosomething= (num) =>
        {
            num = 0;
        };

list lst;

lst.foreach(Dosomething);

    


		System.Predicate<object> Check = (oo) =>
            {
                return true;
            };

 lst.RemoveAll(Check );

action<>,fun<>  ==> 無法多載=.=a

 


		IEnumerable lst1 = (
               from c in plstM
               select c.MID).Distinct();

            IEnumerable lst2 = (
                from c in plstO
                select c.MID).Distinct();

            List lst3 = lst1.Except(lst2).ToList();

 互斥或

 

 


		ooComparer comparer = new ooComparer();
                _datas = _datas.Distinct(comparer).ToList();

class ooComparer : IEqualityComparer
        {
            public bool Equals(League x, League y)
            {
                if (x == null || y == null)
                    return false;
                else
                    return x.Sno == y.Sno || (x.Name_0.ToLower() == y.Name_0.ToLower() && x.WebName.ToLower() == y.WebName.ToLower());
            }

            public int GetHashCode(League obj)
            {
                return (obj.Sno + obj.Name_0 + obj.WebName).GetHashCode();
            }
        }

 

使用指定的 System.Collections.Generic.IEqualityComparer<T> 來比較值,以便從序列傳回獨特的項目

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

===================

搞了C#

現在來學學維修筆電