I am having two array string
Name = new string[3] { "Sachin12", "Nehra123", "Dhoni1" };
Role = new string[3] { "Batsman", "Bowler", "Wicketkeeper" };
fecth the numeric values count from the array "Name"
EX: Sachin having two numeric(1 and 2), nehra having three numeric(1,2 and 3) , dhoni having one numeric values(1). sort this values based on the numeric count like below.
Dhoni
Sachin
Nehra
Their respective "role" should be in the final output. like below
Output should be:
Dhoni Wicketkeeper
Sachin Batsman
Nehra Bowler.
Find The Code Below:
public static void Main(string[] args)
{
var numeri = new HashSet<char>("123");
string[] Name = new string[3];
string[] Role = new string[3];
string[] numeriCount = new string[5];
Name = new string[3] { "Sachin12", "Nehra123", "Dhoni1" };
Role = new string[3] { "Batsman", "Bowler", "Wicketkeeper" };
var vFetchNumeri = from vitem in Name
select new string(vitem.Where(c => numeri.Contains(c)).ToArray());
foreach (var item in vFetchNumeri)
{
int[] newArray = { item.Length };
}
//How to get a numeric count like below
numeriCount = new string[3] { "2", "3", "1"};
Array.Sort(numeriCount, Name);
for (int J = 0; J < Role.Length; J++)
{
Console.WriteLine(Name[J] + " is a " + Role[J]);
}
Console.ReadLine();
}