Summary of IEnumerable usage introduction

零下一度
Release: 2017-06-12 13:07:32
Original
16240 people have browsed it

This article mainly introduces the relevant knowledge of the IEnumerable and IEnumerator interfaces in C#, which has a very good reference value. Let’s take a look at it with the editor. Review the past and learn the new. You can be a teacher. Review the basic knowledge often when you have time. It is necessary and can deepen understanding and memory. Foreach is often used to iterate through collections and traverse containers that implement the IEnumerable interface. I am sometimes a little confused about the IEnumerable and IEnumerator interfaces. According to the official explanation, IEnumerable is an enumerator interface, and IEnumerator is an iterator interface. From the literal meaning See if there is not much difference, let’s analyze them one by one. IEnumerable interface public interface IEnumerable { IEnumerator GetEnumerator(); }Classes that inherit the IEnumerable interface need to implement the exposed GetEnumerator() method and return an IEnum

1. C# A brief introduction to the IEnumerable and IEnumerator interfaces

Summary of IEnumerable usage introduction

Introduction: This article mainly introduces the relevant knowledge of the IEnumerable and IEnumerator interfaces in C#, which has a good reference value. Let’s follow the editor below Let’s take a look

2. Detailed explanation of the graphic code of C# collection type inventory

Summary of IEnumerable usage introduction

Introduction: Collections are an important part of .NET FCL (Framework Class Library) and one of the most commonly used functions in our development. They are almost everywhere. As the saying goes, know what it is and why it is so. When you see IEnumerable, IEnumerator, and ICollection, do you know the differences between them? In addition to List and Dictionary, what other collection classes have you used? Without further ado, today we will take a look at some of the interfaces that define collection classes and their implementations.

3. C# Traps you may not know, detailed explanation of the sample code of the IEnumerable interface

Summary of IEnumerable usage introduction

Introduction: The importance of the IEnumerable enumerator interface cannot be overstated in ten thousand words. Almost all collections implement this interface, and the core of Linq also relies on this universal interface. The for loop in C language is annoying to write, but foreach is much smoother. I like this interface very much, but I also encounter a lot of questions when using it. Do you have the same confusion as me: (1) What is the difference between IEnumerable and IEnumerator? (2) Can enumerations be accessed out of bounds? What are the consequences? Why can't the value of a collection be changed in an enumeration? (3) Li..

4. Detailed explanation of using iterator to traverse file information_PHP tutorial

Introduction : Detailed explanation of using iterator to traverse file information. 1. The code for iterating the lines of the file is as follows: public static IEnumerablestring ReadLines(string fileName) { using (TextReader reader = File.OpenText(fileName)) { string line; if (

5. .Net 2.0 New Features: Iterators

Introduction: What is an iterator? An iterator is a method, get accessor or operator. It enables you to support foreach iteration in a class or structure without having to implement the entire IEnumerable interface. Example: public class YieldTest ... { public static IEnumertablePower( int number, int exponent) ... { int count#.

##[Related Q&A recommendations]:

##asp.net - Type "IEnumerable<>" in MVC6 is defined in an unreferenced assembly

The above is the detailed content of Summary of IEnumerable usage introduction. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!