Home Database Mysql Tutorial .Net 2.0 新功能:迭代器(Iterators)

.Net 2.0 新功能:迭代器(Iterators)

Jun 07, 2016 pm 03:19 PM
.net What new function Iterate

什么是迭代器? 迭代器是方法、 get 访问器或运算符,它能使您能够在类或者结构中支持 foreach 迭代,而不必实现整个 IEnumerable 接口。 例子: public class YieldTest ... { public static IEnumertablePower( int number, int exponent) ... { int count

什么是迭代器?

迭代器是方法、get访问器或运算符,它能使您能够在类或者结构中支持foreach迭代,而不必实现整个IEnumerable接口。

例子:

.Net 2.0 新功能:迭代器(Iterators)public class YieldTest
.Net 2.0 新功能:迭代器(Iterators)
.Net 2.0 新功能:迭代器(Iterators).Net 2.0 新功能:迭代器(Iterators)
...{
.Net 2.0 新功能:迭代器(Iterators)
.Net 2.0 新功能:迭代器(Iterators)   
public static IEnumertable Power(int number ,int exponent)
.Net 2.0 新功能:迭代器(Iterators)
.Net 2.0 新功能:迭代器(Iterators).Net 2.0 新功能:迭代器(Iterators)
...{
.Net 2.0 新功能:迭代器(Iterators)
.Net 2.0 新功能:迭代器(Iterators)   
int counter=0;
.Net 2.0 新功能:迭代器(Iterators)
.Net 2.0 新功能:迭代器(Iterators)   
int result =1;
.Net 2.0 新功能:迭代器(Iterators)
.Net 2.0 新功能:迭代器(Iterators)   
while(counter++ exponent)
.Net 2.0 新功能:迭代器(Iterators)
.Net 2.0 新功能:迭代器(Iterators).Net 2.0 新功能:迭代器(Iterators)
...{
.Net 2.0 新功能:迭代器(Iterators)
.Net 2.0 新功能:迭代器(Iterators)  result 
= result* number
.Net 2.0 新功能:迭代器(Iterators)
.Net 2.0 新功能:迭代器(Iterators)  
yield return result
.Net 2.0 新功能:迭代器(Iterators)
.Net 2.0 新功能:迭代器(Iterators)}

.Net 2.0 新功能:迭代器(Iterators)
.Net 2.0 新功能:迭代器(Iterators)}

.Net 2.0 新功能:迭代器(Iterators)
.Net 2.0 新功能:迭代器(Iterators)}

.Net 2.0 新功能:迭代器(Iterators)


 

1.      迭代器是可以返回相同类型的值的有序序列的一段代码

2.      迭代器可用作方法、运算符或get访问器的代码体

3.      迭代器代码使用yield return语句一次返回每个元素

4.      yield break将终止迭代

5.      可以在类中实现做个迭代器。每个迭代器都必须像任何类成员一样有唯一的名称,并且可以在foreach语句中可调用

6.      迭代器的返回类型必须为IEnumerableIEnumberatorIEnumerbale或者IEnumberator

foreach(int i in YieldTest. Power)

{

 

}

 
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
iPadOS18 new features iPadOS18 new features Jun 12, 2024 pm 10:41 PM

Early this morning, Apple officially released iPadOS18. This system not only has the classic functions of iOS18, but also adds some unique functions, such as supporting mathematical note calculators, etc., which further improves the experience of iPad users. Friends who are interested Come and take a look. This time iPadOS18 not only perfectly inherits the core functions of iOS18, such as the personalized control center design, which allows users to freely adjust the order and layout of control items according to personal preferences, and the highly anticipated game mode, providing gamers with smoother and more The immersive gaming experience also incorporates a number of unique features specifically targeting the iPad’s large screen advantages and the creative uses of Apple Pencil, further expanding the iPad’s productivity.

How to set up the keyboard boot function on a GIGABYTE motherboard (enable keyboard boot mode on GIGABYTE motherboard) How to set up the keyboard boot function on a GIGABYTE motherboard (enable keyboard boot mode on GIGABYTE motherboard) Dec 31, 2023 pm 05:15 PM

How to set up keyboard startup on Gigabyte's motherboard. First, if it needs to support keyboard startup, it must be a PS2 keyboard! ! The setting steps are as follows: Step 1: Press Del or F2 to enter the BIOS after booting, and go to the Advanced (Advanced) mode of the BIOS. Ordinary motherboards enter the EZ (Easy) mode of the motherboard by default. You need to press F7 to switch to the Advanced mode. ROG series motherboards enter the BIOS by default. Advanced mode (we use Simplified Chinese to demonstrate) Step 2: Select to - [Advanced] - [Advanced Power Management (APM)] Step 3: Find the option [Wake up by PS2 keyboard] Step 4: This option The default is Disabled. After pulling down, you can see three different setting options, namely press [space bar] to turn on the computer, press group

What is the best graphics card for i7 3770? What is the best graphics card for i7 3770? Dec 29, 2023 am 09:12 AM

What graphics card is good for Core i73770? RTX3070 is a very powerful graphics card with excellent performance and advanced technology. Whether you're playing games, rendering graphics, or performing machine learning, the RTX3070 can handle it with ease. It uses NVIDIA's Ampere architecture, has 5888 CUDA cores and 8GB of GDDR6 memory, which can provide a smooth gaming experience and high-quality graphics effects. RTX3070 also supports ray tracing technology, which can present realistic light and shadow effects. All in all, the RTX3070 is a powerful and advanced graphics card suitable for those who pursue high performance and high quality. RTX3070 is an NVIDIA series graphics card. Powered by 2nd generation NVID

Microsoft Edge browser's new feature 'Super Drag” is now available! Microsoft Edge browser's new feature 'Super Drag” is now available! Mar 04, 2024 pm 06:31 PM

The editor recently learned that the new feature of Microsoft Edge browser "Super Drag" has been launched, unlocking the fourth way to open links in new tabs, making it easier for users to open links faster. Currently, in the Microsoft Edge browser, if users want to open a link or image in a new tab, there are three ways: 1. Right-click the link or image, and then select the corresponding operation option. 2. Drag the link or image to the tab bar. 3. Use the mouse wheel to click on the link or image. "Super Drag" brings a fourth kind of interaction, where users click on a link, part of text, or image and then drag it sideways, up, or down a little to open it in a new tab. After the user drags the text, the default search engine of the Edge browser will be called by default and a new tab will be opened.

Choosing the right tablet for music students Choosing the right tablet for music students Jan 10, 2024 pm 10:09 PM

Which tablet is suitable for musicians? The 12.9-inch speaker in Huawei’s iPad is a very good product. It comes with four speakers and the sound is excellent. Moreover, it belongs to the pro series, which is slightly better than other styles. Overall, ipad pro is a very good product. The speaker of this mini4 mobile phone is small and the effect is average. It cannot be used to play music externally, you still need to rely on headphones to enjoy music. Headphones with good sound quality will have a slightly better effect, but cheap headphones worth thirty or forty yuan cannot meet the requirements. What tablet should I use for electronic piano music? If you want to buy an iPad larger than 10 inches, I recommend using two applications, namely Henle and Piascore. Provided by Henle

WeChat launches new feature: 'Quiet Mode” WeChat launches new feature: 'Quiet Mode” Mar 04, 2024 pm 01:43 PM

It is understood that WeChat has launched a new feature: "Quiet Mode". After turning it on, WeChat will no longer make sounds in all scenarios such as message notifications, audio and video calls, and video account content playback. Update to the latest version of WeChat on iOS and turn it on through "WeChat" - "Me" - "Settings" - "Care Mode" - "Quiet Mode". After that, WeChat will no longer make sounds in all scenarios such as message notifications, audio and video calls, and video account content playback. WeChat said the feature was developed to meet the needs of those who cannot hear. For most people, sound may be very common and accessible, but they often ignore that the deaf community does not have this perception ability, although they also use mobile phones and WeChat like everyone else. according to

iOS18 new features revealed iOS18 new features revealed Mar 06, 2024 pm 02:25 PM

As Apple is about to release iOS 18, its major annual software update, this will undoubtedly become one of the hot and highly anticipated releases in 2024. According to rumors, this update will be regarded as one of the largest software upgrades in the history of the iPhone. Here is a brief summary of the relevant function upgrades. New iOS 18 feature revelations 1. It is reported that Apple may integrate the visionOS style into iOS 18. , giving people a refreshing operating experience. 2. According to rumors, the company is actively testing AI models and is expected to make major improvements to Siri on the iOS18 version. 3. In addition, Apple has recently launched a pilot program and launched a new tool called "Ask" to AppleCare, aiming to improve the efficiency of customer inquiries. 4

Share several .NET open source AI and LLM related project frameworks Share several .NET open source AI and LLM related project frameworks May 06, 2024 pm 04:43 PM

The development of artificial intelligence (AI) technologies is in full swing today, and they have shown great potential and influence in various fields. Today Dayao will share with you 4 .NET open source AI model LLM related project frameworks, hoping to provide you with some reference. https://github.com/YSGStudyHards/DotNetGuide/blob/main/docs/DotNet/DotNetProjectPicks.mdSemanticKernelSemanticKernel is an open source software development kit (SDK) designed to integrate large language models (LLM) such as OpenAI, Azure

See all articles