SlideShare ist ein Scribd-Unternehmen logo
1 von 4
Downloaden Sie, um offline zu lesen
1.Difference between for and foreach loop

 S.No     For loop                                   Foreach loop
 1        In case of for the variable of the loop is In case of Foreach the variable of the loop
          always be int only.                        while be same as the type of values under the
                                                     array.
 2        The For loop executes the statement or     The Foreach statement repeats a group of
          block of statements repeatedly until       embedded statements for each element in an
          specified expression evaluates to false.   array or an object collection.
 3        There is need to specify the loop          We do not need to specify the loop bounds
          bounds(Minimum, Maximum).                  minimum or maximum.
 4        example:                                   example:
          using sytem;                               using sytem;
           class class1                               class class1
            {                                         {
               static void Main()                         static void Main()
                {                                          {
                   int j=0;                                   int j=0;
                   for(int i=0; i<=10;i++)                    int[] arr=new int[]
                    {                                {0,3,5,2,55,34,643,42,23};
                       j=j+1;                                 foreach(int i in arr)
                     }                                         {
                      Console.ReadLine();                         j=j+1;
                  }                                             }
               }                                                Console.ReadLine();
                                                             }
                                                        }

2. Difference between Covariance and Contravariance

 S.No     Covariance                                 Contravariance
 1        Converting from a broader type to a        Converting from a more specific type to a
          specific type is called co-variance.If B   broader type is called contra-variance. If B is
          is derived from A and B relates to A,      derived from A and B relates to A, then we
          then we can assign A to B. Like A=B.       can assign B to A. Like B= A. This is
          This is Covariance.                        Contravariance.
 2        Co-variance is guaranteed to work         Contra-variance on the other hand is not
          without any loss of information during guaranteed to work without loss of data. As
          conversion. So, most languages also       such an explicit cast is required.
          provide facility for implicit conversion.
                                                    e.g. Converting from cat or dog to animal is
          e.g. Assuming dog and cat inherits from called contra-variance, because not all
          animal, when you convert from animal features (properties/methods) of cat or dog is
          type to dog or cat, it is called co-      present in animal.
          variance.


 3        Example:
class Fruit { }

    class Mango : Fruit { }

    class Program

    {

    delegate T Func<out T>();

    delegate void Action<in T>(T a);

    static void Main(string[] args)

        {

        // Covariance

        Func<Mango> mango = () => new Mango();

        Func<Fruit> fruit = mango;

        // Contravariance

        Action<Fruit> fr = (frt) =>

        { Console.WriteLine(frt); };

        Action<Mango> man = fr;

        }

    }
4   Note:

    1. Co-variance and contra-variance is possible only with reference types; value types
    are invariant.

    2. In .NET 4.0, the support for co-variance and contra-variance has been extended to
    generic types. No now we can apply co-variance and contra-variance to Lists etc. (e.g.
    IEnumerable etc.) that implement a common interface. This was not possible with
    .NET versions 3.5 and earlier.
3.Difference between IList and IEnumerable


 S.No    IList                                      IEnumerable
 1       IList is used to access an element in a    IEnumerable is a forward only collection, it
         specific position/index in a list.         can not move backward and between the
                                                    items.
 2       IList is useful when we want to Add or     IEnumerable does not support add or remove
         remove items from the list.                items from the list.
 3       IList can find out the no of elements in   Using IEnumerable we can find out the no of
         the collection without iterating the       elements in the collection after iterating the
         collection.                                collection.
 4       IList does not support filtering.          IEnumerable supports filtering.

4.Difference between IEnumerable and IQueryable


 S.No    IEnumerable                                IQueryable
 1       IEnumerable exists in                      IQueryable exists in System.Linq
         System.Collections Namespace.              Namespace.
 2       IEnumerable is best to query data from     IQueryable is best to query data from out-
         in-memory collections like List, Array     memory (like remote database, service)
         etc.                                       collections.
 3       While query data from database,            While query data from database,
         IEnumerable execute select query on        IEnumerable execute select query on server
         server side, load data in-memory on        side with all filters.
         client side and then filter data.
 4       IEnumerable is suitable for LINQ to         IQueryable is suitable for LINQ to SQL
         Object and LINQ to XML queries.            queries.
 5       IEnumerable does not supports custom       IQueryable supports custom query using
         query.                                     CreateQuery and Execute methods.
 6       IEnumerable does not support lazy          IQueryable support lazy loading. Hence it is
         loading. Hence not suitable for paging     suitable for paging like scenarios.
         like scenarios.
 7       Extension methods supports by              Extension methods supports by IEnumerable
         IEnumerable takes functional objects.      takes expression objects means expression
                                                    tree.
 8       IEnumerable Example

            MyDataContext dc = new MyDataContext ();
            IEnumerable list = dc.loyees.Where(p => p.Name.StartsWith("S"));
            list = list.Take(10);

         Generated SQL statements of above query will be :

            SELECT [t0].[EmpID], [t0].[EmpName], [t0].[Salary] FROM [Employee] AS [t0]
            WHERE [t0].[EmpName] LIKE @p0
Note: In this query "top 10" is missing since IEnumerable filters records on client side


         IQueryable Example

           MyDataContext dc = new MyDataContext ();
           IEnumerable list = dc.loyees.Where(p => p.Name.StartsWith("S"));
           list = list.Take(10);

         Generated SQL statements of above query will be :

           SELECT TOP 10 [t0].[EmpID], [t0].[EmpName], [t0].[Salary] FROM [Employee]
         AS [t0]
          WHERE [t0].[EmpName] LIKE @p0

         Note: In this query "top 10" is exist since IQueryable executes query in SQL server
         with all filters.

5.Difference between IEnumerable and IEnumerator

 S.No    IEnumerable                               IEnumerator
 1       The IEnumerable interface is a generic    IEnumerator provides two abstract methods
         interface that provides an abstraction    and a property to pull a particular element in
         for looping over elements.                a collection. And they are Reset(),
         In addition to providing foreach          MoveNext() and Current The signature of
         support, it allows us to tap into the     IEnumerator members is as follows:
         useful extension methods in the           void Reset() : Sets the enumerator to its
         System.Linq namespace, opening up a       initial position, which is before the first
         lot of advanced functionality             element in the collection.
         The IEnumerable interface contains an     bool MoveNext() : Advances the enumerator
         abstract member function called           to the next element of the collection.
         GetEnumerator() and return an interface   object Current : Gets the current element in
         IEnumerator on any success call.          the collection
 2       IEnumerable does not remember the         IEnumerator does remember the cursor state
         cursor state i.e currently row which is
         iterating through
 3       IEnumerable is useful when we have        IEnumerator is useful when we have to pass
         only iterate the value                    the iterator as parameter and has to remember
                                                   the value

Weitere ähnliche Inhalte

Was ist angesagt?

Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)
nirajmandaliya
 

Was ist angesagt? (20)

Autoboxing And Unboxing In Java
Autoboxing And Unboxing In JavaAutoboxing And Unboxing In Java
Autoboxing And Unboxing In Java
 
The Awesome Python Class Part-2
The Awesome Python Class Part-2The Awesome Python Class Part-2
The Awesome Python Class Part-2
 
Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
Python The basics
Python   The basicsPython   The basics
Python The basics
 
What's New In Python 2.5
What's New In Python 2.5What's New In Python 2.5
What's New In Python 2.5
 
Double pointer (pointer to pointer)
Double pointer (pointer to pointer)Double pointer (pointer to pointer)
Double pointer (pointer to pointer)
 
What's New In Python 2.4
What's New In Python 2.4What's New In Python 2.4
What's New In Python 2.4
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statements
 
Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)
 
python Function
python Function python Function
python Function
 
Python Closures Explained | What are Closures in Python | Python Closures
Python Closures Explained | What are Closures in Python | Python ClosuresPython Closures Explained | What are Closures in Python | Python Closures
Python Closures Explained | What are Closures in Python | Python Closures
 
M C6java3
M C6java3M C6java3
M C6java3
 
Chapter 7 String
Chapter 7 StringChapter 7 String
Chapter 7 String
 
05 object behavior
05 object behavior05 object behavior
05 object behavior
 
Advance python
Advance pythonAdvance python
Advance python
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.com
 
Python programming
Python  programmingPython  programming
Python programming
 
DISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in JavaDISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in Java
 
Pointers
PointersPointers
Pointers
 
Pointers
PointersPointers
Pointers
 

Ähnlich wie Dotnet programming concepts difference faqs- 2

Python For Data Science.pptx
Python For Data Science.pptxPython For Data Science.pptx
Python For Data Science.pptx
rohithprabhas1
 
C language presentation
C language presentationC language presentation
C language presentation
bainspreet
 

Ähnlich wie Dotnet programming concepts difference faqs- 2 (20)

Python For Data Science.pptx
Python For Data Science.pptxPython For Data Science.pptx
Python For Data Science.pptx
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
python interview prep question , 52 questions
python interview prep question , 52 questionspython interview prep question , 52 questions
python interview prep question , 52 questions
 
computer notes - Reference variables
computer notes -  Reference variablescomputer notes -  Reference variables
computer notes - Reference variables
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
C language presentation
C language presentationC language presentation
C language presentation
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptx
 
GE3151 UNIT II Study material .pdf
GE3151 UNIT II Study material .pdfGE3151 UNIT II Study material .pdf
GE3151 UNIT II Study material .pdf
 
functions- best.pdf
functions- best.pdffunctions- best.pdf
functions- best.pdf
 
Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops concept
 
Basic of Python- Hands on Session
Basic of Python- Hands on SessionBasic of Python- Hands on Session
Basic of Python- Hands on Session
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
 
Java String
Java String Java String
Java String
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers
 
Notes on c++
Notes on c++Notes on c++
Notes on c++
 
Basic_Java_02.pptx
Basic_Java_02.pptxBasic_Java_02.pptx
Basic_Java_02.pptx
 
functions-.pdf
functions-.pdffunctions-.pdf
functions-.pdf
 
Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning
 

Mehr von Umar Ali

Mehr von Umar Ali (20)

Difference between wcf and asp.net web api
Difference between wcf and asp.net web apiDifference between wcf and asp.net web api
Difference between wcf and asp.net web api
 
Difference between ActionResult() and ViewResult()
Difference between ActionResult() and ViewResult()Difference between ActionResult() and ViewResult()
Difference between ActionResult() and ViewResult()
 
Difference between asp.net mvc 3 and asp.net mvc 4
Difference between asp.net mvc 3 and asp.net mvc 4Difference between asp.net mvc 3 and asp.net mvc 4
Difference between asp.net mvc 3 and asp.net mvc 4
 
Difference between asp.net web api and asp.net mvc
Difference between asp.net web api and asp.net mvcDifference between asp.net web api and asp.net mvc
Difference between asp.net web api and asp.net mvc
 
Difference between asp.net web forms and asp.net mvc
Difference between asp.net web forms and asp.net mvcDifference between asp.net web forms and asp.net mvc
Difference between asp.net web forms and asp.net mvc
 
ASP.NET MVC difference between questions list 1
ASP.NET MVC difference between questions list 1ASP.NET MVC difference between questions list 1
ASP.NET MVC difference between questions list 1
 
Link checkers 1
Link checkers 1Link checkers 1
Link checkers 1
 
Affiliate Networks Sites-1
Affiliate Networks Sites-1Affiliate Networks Sites-1
Affiliate Networks Sites-1
 
Technical Video Training Sites- 1
Technical Video Training Sites- 1Technical Video Training Sites- 1
Technical Video Training Sites- 1
 
US News Sites- 1
US News Sites- 1 US News Sites- 1
US News Sites- 1
 
How to create user friendly file hosting link sites
How to create user friendly file hosting link sitesHow to create user friendly file hosting link sites
How to create user friendly file hosting link sites
 
Weak hadiths in tamil
Weak hadiths in tamilWeak hadiths in tamil
Weak hadiths in tamil
 
Bulughul Maram in tamil
Bulughul Maram in tamilBulughul Maram in tamil
Bulughul Maram in tamil
 
Asp.net website usage and job trends
Asp.net website usage and job trendsAsp.net website usage and job trends
Asp.net website usage and job trends
 
Indian news sites- 1
Indian news sites- 1 Indian news sites- 1
Indian news sites- 1
 
Photo sharing sites- 1
Photo sharing sites- 1 Photo sharing sites- 1
Photo sharing sites- 1
 
File hosting search engines
File hosting search enginesFile hosting search engines
File hosting search engines
 
Ajax difference faqs compiled- 1
Ajax difference  faqs compiled- 1Ajax difference  faqs compiled- 1
Ajax difference faqs compiled- 1
 
ADO.NET difference faqs compiled- 1
ADO.NET difference  faqs compiled- 1ADO.NET difference  faqs compiled- 1
ADO.NET difference faqs compiled- 1
 
Dotnet differences compiled -1
Dotnet differences compiled -1Dotnet differences compiled -1
Dotnet differences compiled -1
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Dotnet programming concepts difference faqs- 2

  • 1. 1.Difference between for and foreach loop S.No For loop Foreach loop 1 In case of for the variable of the loop is In case of Foreach the variable of the loop always be int only. while be same as the type of values under the array. 2 The For loop executes the statement or The Foreach statement repeats a group of block of statements repeatedly until embedded statements for each element in an specified expression evaluates to false. array or an object collection. 3 There is need to specify the loop We do not need to specify the loop bounds bounds(Minimum, Maximum). minimum or maximum. 4 example: example: using sytem; using sytem; class class1 class class1 { { static void Main() static void Main() { { int j=0; int j=0; for(int i=0; i<=10;i++) int[] arr=new int[] { {0,3,5,2,55,34,643,42,23}; j=j+1; foreach(int i in arr) } { Console.ReadLine(); j=j+1; } } } Console.ReadLine(); } } 2. Difference between Covariance and Contravariance S.No Covariance Contravariance 1 Converting from a broader type to a Converting from a more specific type to a specific type is called co-variance.If B broader type is called contra-variance. If B is is derived from A and B relates to A, derived from A and B relates to A, then we then we can assign A to B. Like A=B. can assign B to A. Like B= A. This is This is Covariance. Contravariance. 2 Co-variance is guaranteed to work Contra-variance on the other hand is not without any loss of information during guaranteed to work without loss of data. As conversion. So, most languages also such an explicit cast is required. provide facility for implicit conversion. e.g. Converting from cat or dog to animal is e.g. Assuming dog and cat inherits from called contra-variance, because not all animal, when you convert from animal features (properties/methods) of cat or dog is type to dog or cat, it is called co- present in animal. variance. 3 Example:
  • 2. class Fruit { } class Mango : Fruit { } class Program { delegate T Func<out T>(); delegate void Action<in T>(T a); static void Main(string[] args) { // Covariance Func<Mango> mango = () => new Mango(); Func<Fruit> fruit = mango; // Contravariance Action<Fruit> fr = (frt) => { Console.WriteLine(frt); }; Action<Mango> man = fr; } } 4 Note: 1. Co-variance and contra-variance is possible only with reference types; value types are invariant. 2. In .NET 4.0, the support for co-variance and contra-variance has been extended to generic types. No now we can apply co-variance and contra-variance to Lists etc. (e.g. IEnumerable etc.) that implement a common interface. This was not possible with .NET versions 3.5 and earlier.
  • 3. 3.Difference between IList and IEnumerable S.No IList IEnumerable 1 IList is used to access an element in a IEnumerable is a forward only collection, it specific position/index in a list. can not move backward and between the items. 2 IList is useful when we want to Add or IEnumerable does not support add or remove remove items from the list. items from the list. 3 IList can find out the no of elements in Using IEnumerable we can find out the no of the collection without iterating the elements in the collection after iterating the collection. collection. 4 IList does not support filtering. IEnumerable supports filtering. 4.Difference between IEnumerable and IQueryable S.No IEnumerable IQueryable 1 IEnumerable exists in IQueryable exists in System.Linq System.Collections Namespace. Namespace. 2 IEnumerable is best to query data from IQueryable is best to query data from out- in-memory collections like List, Array memory (like remote database, service) etc. collections. 3 While query data from database, While query data from database, IEnumerable execute select query on IEnumerable execute select query on server server side, load data in-memory on side with all filters. client side and then filter data. 4 IEnumerable is suitable for LINQ to IQueryable is suitable for LINQ to SQL Object and LINQ to XML queries. queries. 5 IEnumerable does not supports custom IQueryable supports custom query using query. CreateQuery and Execute methods. 6 IEnumerable does not support lazy IQueryable support lazy loading. Hence it is loading. Hence not suitable for paging suitable for paging like scenarios. like scenarios. 7 Extension methods supports by Extension methods supports by IEnumerable IEnumerable takes functional objects. takes expression objects means expression tree. 8 IEnumerable Example MyDataContext dc = new MyDataContext (); IEnumerable list = dc.loyees.Where(p => p.Name.StartsWith("S")); list = list.Take(10); Generated SQL statements of above query will be : SELECT [t0].[EmpID], [t0].[EmpName], [t0].[Salary] FROM [Employee] AS [t0] WHERE [t0].[EmpName] LIKE @p0
  • 4. Note: In this query "top 10" is missing since IEnumerable filters records on client side IQueryable Example MyDataContext dc = new MyDataContext (); IEnumerable list = dc.loyees.Where(p => p.Name.StartsWith("S")); list = list.Take(10); Generated SQL statements of above query will be : SELECT TOP 10 [t0].[EmpID], [t0].[EmpName], [t0].[Salary] FROM [Employee] AS [t0] WHERE [t0].[EmpName] LIKE @p0 Note: In this query "top 10" is exist since IQueryable executes query in SQL server with all filters. 5.Difference between IEnumerable and IEnumerator S.No IEnumerable IEnumerator 1 The IEnumerable interface is a generic IEnumerator provides two abstract methods interface that provides an abstraction and a property to pull a particular element in for looping over elements. a collection. And they are Reset(), In addition to providing foreach MoveNext() and Current The signature of support, it allows us to tap into the IEnumerator members is as follows: useful extension methods in the void Reset() : Sets the enumerator to its System.Linq namespace, opening up a initial position, which is before the first lot of advanced functionality element in the collection. The IEnumerable interface contains an bool MoveNext() : Advances the enumerator abstract member function called to the next element of the collection. GetEnumerator() and return an interface object Current : Gets the current element in IEnumerator on any success call. the collection 2 IEnumerable does not remember the IEnumerator does remember the cursor state cursor state i.e currently row which is iterating through 3 IEnumerable is useful when we have IEnumerator is useful when we have to pass only iterate the value the iterator as parameter and has to remember the value