using 2 for loops and comparing the data with data table

Padmanabhan, Venkatesh 120 Reputation points
2023-04-12T04:09:02.6633333+00:00

Hi. I have 2 string arrays, which are of similar length. Example: if Array1 has values - John, Ron, Max , Array2 has values - 20, 45, 10 I have a data table which has the column - Name, Marks. Name has values of John, Ron and Max. I want to compare the datatable column Name with the Array1 , and if matches, then I want to set the Marks column corresponding to it. If John is matched, then marks should be 20 , Ron is matched then marks to be set as 45.. I have tried the first loop of comparing, but not sure, how to set the second loop for Array2. How to fix this ?

// DataTable is dataResult
 string[] names = new string[] { };  //  contains names
 string[] marks = new string[] { };  //  contains marks
 foreach (DataRow row in dataResult.Rows)
 {
 for (int i = 0; i < names.Length; i++)
  {
   if (names[i].Equals(row["USER_NAME"]))
   {
// to match the mark
   }
  }
}
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,373 questions
0 comments No comments
{count} votes

0 additional answers

Sort by: Most helpful