Hi Team,
i have following array,
i want the output as below from Mentioned Array
Student1 80
Student2 90
Student3 100
Student4 80
would this be possible by LINQ… pls help
Hi Team,
i have following array,
i want the output as below from Mentioned Array
Student1 80
Student2 90
Student3 100
Student4 80
would this be possible by LINQ… pls help
Still a bit not clear on the Output representation, but could check with the below if it is the Expectation :
Array2.Chunk(2).Select(Function(x)String.Join(" ",x)).ToArray
From Debug :
If you have the need to store the values in the array in a DT then, you could use a simple counter based loop to achieve this.
wordked Bro… THanks dear… is there any Documentation you can share to understand LINQ Functions
Would suggest to go through the Tutorial/Docs on the below post :
The content keeps on getting updated in the post.
Also, Could refer on some Youtube videos :
Array:
string data = { “Student1”, “80”, “Student2”, “90”, “Student3”, “100”, “Student4”, “80” };
Use this Linq:
var result = data.Select((value, index) => new { Student = value, Score = data[index + 1] })
.Where((item, index) => index % 2 == 0)
.Select(item => $“{item.Student} {item.Score}”);
Select
method to project the array elements into pairs of “Student” and “Score” based on their positions in the array.Where
method to filter out every other item, starting with the first one (index 0), effectively selecting the “Student” elements.Select
to format the pairs as “Student Score” strings, which is your desired output.Output:
Student1 80
Student2 90
Student3 100
Student4 80
Cheers…!