Click here to Skip to main content
15,893,668 members
Home / Discussions / C#
   

C#

 
GeneralRe: File csproj : how to create a nuget package with msbuild and with package dependencies ? Pin
chris_brabant16-Aug-23 21:33
chris_brabant16-Aug-23 21:33 
GeneralRe: File csproj : how to create a nuget package with msbuild and with package dependencies ? Pin
Richard Deeming16-Aug-23 21:52
mveRichard Deeming16-Aug-23 21:52 
Questionhow to edit and delete lines from a text file Pin
Edilson Lemos 202112-Aug-23 12:36
Edilson Lemos 202112-Aug-23 12:36 
AnswerRe: how to edit and delete lines from a text file PinPopular
OriginalGriff12-Aug-23 19:01
mveOriginalGriff12-Aug-23 19:01 
GeneralRe: how to edit and delete lines from a text file Pin
Edilson Lemos 202113-Aug-23 11:15
Edilson Lemos 202113-Aug-23 11:15 
GeneralRe: how to edit and delete lines from a text file Pin
OriginalGriff13-Aug-23 19:08
mveOriginalGriff13-Aug-23 19:08 
AnswerRe: how to edit and delete lines from a text file Pin
Gerry Schmitz13-Aug-23 5:53
mveGerry Schmitz13-Aug-23 5:53 
AnswerRe: how to edit and delete lines from a text file Pin
jschell14-Aug-23 6:07
jschell14-Aug-23 6:07 
Questionthen the new student submits their answer to ... Pin
BillWoodruff8-Aug-23 4:23
professionalBillWoodruff8-Aug-23 4:23 
AnswerRe: then the new student submits their answer to ... Pin
Pete O'Hanlon8-Aug-23 19:33
mvePete O'Hanlon8-Aug-23 19:33 
GeneralRe: then the new student submits their answer to ... Pin
BillWoodruff10-Aug-23 0:36
professionalBillWoodruff10-Aug-23 0:36 
GeneralRe: then the new student submits their answer to ... Pin
Pete O'Hanlon10-Aug-23 3:29
mvePete O'Hanlon10-Aug-23 3:29 
GeneralRe: then the new student submits their answer to ... Pin
BillWoodruff10-Aug-23 2:09
professionalBillWoodruff10-Aug-23 2:09 
GeneralRe: then the new student submits their answer to ... Pin
Richard MacCutchan10-Aug-23 2:26
mveRichard MacCutchan10-Aug-23 2:26 
GeneralRe: then the new student submits their answer to ... Pin
Richard Deeming10-Aug-23 2:42
mveRichard Deeming10-Aug-23 2:42 
GeneralRe: then the new student submits their answer to ... Pin
BillWoodruff10-Aug-23 12:38
professionalBillWoodruff10-Aug-23 12:38 
GeneralRe: then the new student submits their answer to ... Pin
Richard Deeming10-Aug-23 21:27
mveRichard Deeming10-Aug-23 21:27 
GeneralRe: then the new student submits their answer to ... Pin
Richard Deeming10-Aug-23 23:27
mveRichard Deeming10-Aug-23 23:27 
GeneralRe: then the new student submits their answer to ... Pin
Sandeep Mewara12-Aug-23 17:26
mveSandeep Mewara12-Aug-23 17:26 
QuestionCount DataGridview row values and compare with an Array (Resolved) Pin
Edilson Lemos 20217-Aug-23 14:21
Edilson Lemos 20217-Aug-23 14:21 
AnswerRe: Count DataGridview row values and compare with an Array Pin
OriginalGriff7-Aug-23 19:56
mveOriginalGriff7-Aug-23 19:56 
AnswerRe: Count DataGridview row values and compare with an Array Pin
Andre Oosthuizen7-Aug-23 22:46
mveAndre Oosthuizen7-Aug-23 22:46 
Your code is storing the repeated counts as keys in the dictionary, which results in multiple repetitions being displayed in a single row in the DataGridView in your 'Acertos' cell.

You need to store the dictionary values to store the count of repetitions for each line, rather than the repeated count itself -

C#
private IDictionary<int, int> GetResultFromTextFile(IEnumerable<int> src)
{
    var filePath = @"C:\BoaSorte\Banco\testeResultado.txt";
    var delimiter = new[] { ' ' };
    var dict = File.ReadLines(filePath)
        .Where(line => !string.IsNullOrEmpty(line))
        .Aggregate(new Dictionary<int, int>(), (d, line) =>
        {
            var values = line
                .Split(delimiter, StringSplitOptions.RemoveEmptyEntries)
                .Select(x => int.Parse(x));
            var matchCount = values.Count(v => src.Contains(v)); //Count all matches...

            if (d.ContainsKey(matchCount))
                d[matchCount]++;
            else
                d[matchCount] = 1; //Store the count of repetitions, not the repeated count...

            return d;
        });

    return dict;
}

private void button1_Click(object sender, EventArgs e)
{
    int outVal;

    if (UltimoResultado.Any(Acertos => !int.TryParse(Acertos.Text, out outVal)))
    {
        MessageBox.Show("Valores Invalidos...");
        return;
    }
    
    var arr = UltimoResultado.Select(linha => int.Parse(linha.Text));
    var result = GetResultFromTextFile(arr).ToList();
    
    for (int i = 0; i < result.Count; i++)
    {
        dgHits.Rows[i].Cells["Acertos"].Value = result[i].Value.ToString(); //Display the value, not the key...
    }
}

GeneralRe: Count DataGridview row values and compare with an Array Pin
Edilson Lemos 20219-Aug-23 14:00
Edilson Lemos 20219-Aug-23 14:00 
GeneralRe: Count DataGridview row values and compare with an Array Pin
Andre Oosthuizen9-Aug-23 21:24
mveAndre Oosthuizen9-Aug-23 21:24 
SuggestionRe: Count DataGridview row values and compare with an Array Pin
Richard Deeming9-Aug-23 21:51
mveRichard Deeming9-Aug-23 21:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.