Skip to content

Instantly share code, notes, and snippets.

@ironpython2001
Created May 6, 2022 08:36
Show Gist options
  • Save ironpython2001/aac30abf36bfbfc30b124129f40a312f to your computer and use it in GitHub Desktop.
Save ironpython2001/aac30abf36bfbfc30b124129f40a312f to your computer and use it in GitHub Desktop.
even before odd numbers in c#
//even before odd numbers
//Input Result
//[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] [2, 4, 6, 8, 10, 3, 7, 1, 9, 5]
//[2, 4, 6, 1, 8] [2, 4, 6, 8, 1]
//[2, 4, 6, 8, 1] [2, 4, 6, 8, 1]
var lst = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var lstEven = new List<int>();
var lstOdd = new List<int>();
foreach (var i in lst)
{
if (i % 2 == 0)
{
lstEven.Add(i);
}
else
{
lstOdd.Add(i);
}
}
var res = lstEven.Concat(lstOdd).ToList();
res.ForEach(i=> Console.WriteLine(i));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment