Sto utilizzando Elenco in C#. Codice è come indicato di seguito:Trova il conteggio di elementi duplicati in un elenco C#
TestCase.cs
public class TestCase
{
private string scenarioID;
private string error;
public string ScenarioID
{
get
{
return this.scenarioID;
}
set
{
this.scenarioID = value;
}
}
public string Error
{
get
{
return this.error;
}
set
{
this.error = value;
}
}
public TestCase(string arg_scenarioName, string arg_error)
{
this.ScenarioID = arg_scenarioName;
this.Error = arg_error;
}
}
Lista sto createing è:
private List<TestCase> GetTestCases()
{
List<TestCase> scenarios = new List<TestCase>();
TestCase scenario1 = new TestCase("Scenario1", string.Empty);
TestCase scenario2 = new TestCase("Scenario2", string.Empty);
TestCase scenario3 = new TestCase("Scenario1", string.Empty);
TestCase scenario4 = new TestCase("Scenario4", string.Empty);
TestCase scenario5 = new TestCase("Scenario1", string.Empty);
TestCase scenario6 = new TestCase("Scenario6", string.Empty);
TestCase scenario7 = new TestCase("Scenario7", string.Empty);
scenarios.Add(scenario1);
scenarios.Add(scenario2);
scenarios.Add(scenario3);
scenarios.Add(scenario4);
scenarios.Add(scenario5);
scenarios.Add(scenario6);
scenarios.Add(scenario7);
return scenarios;
}
Ora sto scorrendo l'elenco. Voglio trovare il numero di test duplicati presenti in un elenco con lo stesso ScenarioID. C'è un modo per risolverlo usando Linq o qualsiasi metodo integrato per List?
saluti, Priyank
Qual è la risposta nel tuo esempio? 1, 2 o 3 (o altro)? –
http://stackoverflow.com/questions/5080538/c-sharp-determine-duplicate-in-list – assylias
Perché è necessario contare gli elementi duplicati? (Curioso) –