Skip to content

Instantly share code, notes, and snippets.

@ruhelaanurag
Last active April 12, 2020 05:29
Show Gist options
  • Save ruhelaanurag/9afcb93a49e75577a1839d11138722bb to your computer and use it in GitHub Desktop.
Save ruhelaanurag/9afcb93a49e75577a1839d11138722bb to your computer and use it in GitHub Desktop.
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