string[] num = {"1"",2"",3"",4"",5"",6"}; // this array is used to display
You want to divide it into two arrays:
How do I divide an array into two arrays?
string[] odd = {"1","3","5"};
string[] even = {"2","4","5"};
Try using LINQ of C#.
using System.LINQ;
// ...
var odd = num.Where(str => (Int32.Parse(str)%2)==1);
var even = num.Where(str => (Int32.Parse(str)%2)==0);
Reference link
[1] https://www.dotnetperls.com/linq
Code Execution Example
using System;
using System.Linq;
public class Hello1 {
public static void Main() {
string[] num = {"1","2","3","4","5","6"};
var odd = num.Where(str => (Int32.Parse(str)%2)==1);
Console.WriteLine("ODD");
foreach (string value in odd)
{
Console.WriteLine(value);
}
var even = num.Where(str => (Int32.Parse(str)%2)==0);
Console.WriteLine("EVEN");
foreach (string value in even)
{
Console.WriteLine(value);
}
}
}
© 2025 OneMinuteCode. All rights reserved.