سلام بر تمامی برنامه نویسان عزیز 😉 در این مطلب کد مقدار yield برای IEnumerable در سی شارپ #C را آماده کردم. انشاالله که این کد براتون مفید باشه.
خروجی این کد به صورت زیر می باشد:
1
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
کد مقدار yield برای IEnumerable در سی شارپ #C :
using System;
using System.Collections.Generic;
public class MainClass
{
static public IEnumerable<int> Powers( int from,
int to ) {
for( int i = from; i <= to; ++i ) {
yield return (int) Math.Pow( 2, i );
using System.Collections.Generic;
public class MainClass
{
static public IEnumerable<int> Powers( int from,
int to ) {
for( int i = from; i <= to; ++i ) {
yield return (int) Math.Pow( 2, i );