Last active
April 12, 2020 05:29
-
-
Save ruhelaanurag/9afcb93a49e75577a1839d11138722bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
Console.WriteLine("Hello World"); | |
Program prog = new Program(); | |
foreach (var even in prog.GetEvenNumbers(10000000)) | |
{ | |
Console.WriteLine(even); | |
} | |
foreach (var even in prog.GetEvenList(10000000)) | |
{ | |
Console.WriteLine(even); | |
} | |
} | |
public List<int> GetEvenList(int numbersTill) | |
{ | |
var lstEvenNumbers = new List<int>(); | |
for (int i = 0; i <= numbersTill; i = i + 2) | |
{ | |
lstEvenNumbers.Add(i); | |
} | |
return lstEvenNumbers; | |
} | |
public IEnumerable<int> GetEvenNumbers(int numbersTill) | |
{ | |
for (int i = 0; i <= numbersTill; i = i + 2) | |
{ | |
yield return i; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment