首页 > 其他 > 详细

LINQ

时间:2019-03-05 20:50:36      阅读:191      评论:0      收藏:0      [点我收藏+]

IEnumerable、IEnumerator

这两个接口位于System.Collections.Generic命名空间下。
IEnumrable
源码:https://referencesource.microsoft.com/#mscorlib/system/collections/ienumerable.cs,9be451ac13d86a97

[Guid("496B0ABE-CDEE-11d3-88E8-00902754C43A")]
[System.Runtime.InteropServices.ComVisible(true)]
public interface IEnumerable
{
        // Interfaces are not serializable
        // Returns an IEnumerator for this enumerable Object.  The enumerator provides
        // a simple way to access all the contents of a collection.
        [Pure]
        [DispId(-4)]
        IEnumerator GetEnumerator();
}

实际上就一个方法:IEnumerator GetEnumerator();

IEnumerator
源码:

public interface IEnumerator
    {
        // Interfaces are not serializable
        // Advances the enumerator to the next element of the enumeration and
        // returns a boolean indicating whether an element is available. Upon
        // creation, an enumerator is conceptually positioned before the first
        // element of the enumeration, and the first call to MoveNext 
        // brings the first element of the enumeration into view.
        // 
        bool MoveNext();
    
        // Returns the current element of the enumeration. The returned value is
        // undefined before the first call to MoveNext and following a
        // call to MoveNext that returned false. Multiple calls to
        // GetCurrent with no intervening calls to MoveNext 
        // will return the same object.
        // 
        Object Current {
            get; 
        }
    
        // Resets the enumerator to the beginning of the enumeration, starting over.
        // The preferred behavior for Reset is to return the exact same enumeration.
        // This means if you modify the underlying collection then call Reset, your
        // IEnumerator will be invalid, just as it would have been if you had called
        // MoveNext or Current.
        //
        void Reset();
    }

很明显,如果一个类实现了这两个方法,就能遍历该类所包含的一些数据。为了使用更加方便,c#更是用foreach关键字来简化使用。

var

匿名类型(隐式类型),就是让编译器猜测数据类型。

var i = new int[] {1,2,3}; //编译器能猜出来`i`是个int数组。

匿名类

var i = new {name = "kun",age ="20"};

我们并没有定义一个类,但是使用的时候直接i.name就能得到kun字符串。

lambda表达式

表达式树

扩展方法

namespace SqlSugar
{
    public class JoinQueryInfo
    {
        public JoinType JoinType{ get; set; }
        public string TableName { get; set; }
        public string ShortName { get; set; }
        public int JoinIndex { get; set; }
        public string JoinWhere { get; set; }
    }
}

LINQ

原文:https://www.cnblogs.com/feipeng8848/p/10479057.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!