void AnalaysisFunc(List<CameraResult> camResult,bool IsFront) { CameraResult finalResult = new CameraResult(); for (int i = 0; i < camResult.Count; i++) { string[] key = { camResult[i].CarNoAr, camResult[i].CarNoEn, camResult[i].CitryCodeAr, camResult[i].CityCodeEn, camResult[i].CountryCode }; int[] repeatation = { 0, 0, 0, 0, 0 }; foreach (CameraResult cam in camResult) { if (cam.CarNoAr == key[0]) { repeatation[0]++; } if (cam.CarNoEn == key[1]) { repeatation[1]++; } if (cam.CitryCodeAr == key[2]) { repeatation[2]++; } if (cam.CityCodeEn == key[3]) { repeatation[3]++; } if (cam.CountryCode == key[4]) { repeatation[4]++; } } if (repeatation[0] >= camResult.Count / 2) { finalResult.CarNoAr = key[0]; } if (repeatation[1] >= camResult.Count / 2) { finalResult.CarNoEn = key[1]; } if (repeatation[2] >= camResult.Count / 2) { finalResult.CitryCodeAr = key[2]; } if (repeatation[3] >= camResult.Count / 2) { finalResult.CityCodeEn = key[3]; } if (repeatation[4] >= camResult.Count / 2) { finalResult.CountryCode = key[4]; } } //in case of cann't find repeatation take the last read in the list if (camResult.Count > 0) { if (string.IsNullOrEmpty(finalResult.CarNoAr)) { finalResult.CarNoAr = camResult[camResult.Count - 1].CarNoAr; } if (string.IsNullOrEmpty(finalResult.CarNoEn)) { finalResult.CarNoEn = camResult[camResult.Count - 1].CarNoEn; } if (string.IsNullOrEmpty(finalResult.CityCodeEn)) { finalResult.CityCodeEn = camResult[camResult.Count - 1].CityCodeEn; } if (string.IsNullOrEmpty(finalResult.CitryCodeAr)) { finalResult.CitryCodeAr = camResult[camResult.Count - 1].CitryCodeAr; } if (string.IsNullOrEmpty(finalResult.CountryCode)) { finalResult.CountryCode = camResult[camResult.Count - 1].CountryCode; } if (IsFront) { this.ForntCamThread = finalResult; startAnalysisFront = false; camResultFront.Clear(); } else { this.BackCamThread = finalResult; startAnalysisback = false; camResultBack.Clear(); } } } public class CameraResult { public CameraResult() { } public CameraResult(string CountryCode, string CityCodeAr, string CityCodeEn,string carnoAr,string carNoEn) { this.CountryCode = CountryCode; this.CityCodeEn = CityCodeEn; this.CitryCodeAr = CityCodeAr; this.CarNoAr = carnoAr; this.CarNoEn = carNoEn; } string countryCode; public string CountryCode { get { return countryCode; } set { countryCode = value; } } string citryCodeAr; public string CitryCodeAr { get { return citryCodeAr; } set { citryCodeAr = value; } } string cityCodeEn; public string CityCodeEn { get { return cityCodeEn; } set { cityCodeEn = value; } } string carNoAr; public string CarNoAr { get { return carNoAr; } set { carNoAr = value; } } string carNoEn; public string CarNoEn { get { return carNoEn; } set { carNoEn = value; } } } Is that a good way to achieve this goal with less iteration to get more performance in my case if I have list items 10 I My iteration no will be 100
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)