Hi
I have below code & i want only distinct records in StudentCollection.
C#
List objResult = bALSessionDeliveryParticipant.GetSessionDeliveryParticipantList(Convert.ToDateTime("2020-01-01"), Utility.CurrentDateTime(), MentorCollection, GroupCollection);
if (objResult != null)
{
foreach (var colum in objResult)
{
StudentCollection.Add(colum.StudentID.ToString());
}
}Thanks

Amit MohantyRank #112 · 20K reputationPosted May 29, 2023, 1:39 AM EDT
try this:
List objResult = bALSessionDeliveryParticipant.GetSessionDeliveryParticipantList(Convert.ToDateTime("2020-01-01"), Utility.CurrentDateTime(), MentorCollection, GroupCollection); if (objResult != null) { StudentCollection = objResult.Select(colum => colum.StudentID.ToString()).Distinct().ToList(); }Aravind GovindarajRank #430 · 5.8K reputationPosted May 28, 2023, 1:49 PM EDT
Hi Ramco,
you could get the desired result in a couple of approaches
1. you can get a distinct result from the backend in the get method (bALSessionDeliveryParticipant.GetSessionDeliveryParticipantList)
2. Before adding to StudentCollection, please check if the student id already exists in the collection.
if ! (StudentCollection.Any(x=>x.StudentId == column.StudentID)
{
StudentCollection.Add(colum.StudentID.ToString());
}