Created
May 6, 2022 08:36
-
-
Save ironpython2001/aac30abf36bfbfc30b124129f40a312f to your computer and use it in GitHub Desktop.
even before odd numbers in c#
This file contains hidden or 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
//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