Click here to Skip to main content
15,793,609 members
Home / Discussions / C#
   

C#

 
GeneralRe: then the new student submits their answer to ... Pin
BillWoodruff10-Aug-23 3:09
professionalBillWoodruff10-Aug-23 3:09 
GeneralRe: then the new student submits their answer to ... Pin
Richard MacCutchan10-Aug-23 3:26
mveRichard MacCutchan10-Aug-23 3:26 
GeneralRe: then the new student submits their answer to ... Pin
Richard Deeming10-Aug-23 3:42
mveRichard Deeming10-Aug-23 3:42 
GeneralRe: then the new student submits their answer to ... Pin
BillWoodruff10-Aug-23 13:38
professionalBillWoodruff10-Aug-23 13:38 
GeneralRe: then the new student submits their answer to ... Pin
Richard Deeming10-Aug-23 22:27
mveRichard Deeming10-Aug-23 22:27 
GeneralRe: then the new student submits their answer to ... Pin
Richard Deeming11-Aug-23 0:27
mveRichard Deeming11-Aug-23 0:27 
GeneralRe: then the new student submits their answer to ... Pin
Sandeep Mewara12-Aug-23 18:26
mveSandeep Mewara12-Aug-23 18:26 
QuestionCount DataGridview row values and compare with an Array (Resolved) Pin
Edilson Lemos 20217-Aug-23 15:21
Edilson Lemos 20217-Aug-23 15:21 
I'm populating a Datagriview from a text file with several lines with 15 numbers each, these numbers change every day, as well as the number of lines.
Ex:
*01 05 08 09 10 12 15 16 17 18 19 20 22 24 25

*02 07 08 09 10 11 15 16 17 18 20 21 22 24 25

*01 07 08 09 10 12 13 15 17 18 19 20 21 22 25

I also have an array that generates 15 random numbers between 01 and 25,
ex: 01 02 04 05 08 09 13 15 16 17 18 19 20 22 25

I need to count how many numbers in each line are repeated with the numbers in the array.
tenho seguinte codigo, mas não me traz um resultado satisfatório.
C#
<pre> 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.Where(v => src.Contains(v)).Count();

                    if (matchCount <= 15)
                    {
                        if (d.ContainsKey(matchCount))
                            d[matchCount]++;
                        else
                            d[matchCount] = matchCount;
                    }
                    return d;
                });

            return dict;
        }
<pre>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].ToString();                
            }
        }



a picture of how i'm receiving

how am i receiving

how do i need it to appear

thank you in advance for any comments

modified 20-Aug-23 23:06pm.

AnswerRe: Count DataGridview row values and compare with an Array Pin
OriginalGriff7-Aug-23 20:56
mvaOriginalGriff7-Aug-23 20:56 
AnswerRe: Count DataGridview row values and compare with an Array Pin
Andre Oosthuizen7-Aug-23 23:46
mveAndre Oosthuizen7-Aug-23 23:46 
GeneralRe: Count DataGridview row values and compare with an Array Pin
Edilson Lemos 20219-Aug-23 15:00
Edilson Lemos 20219-Aug-23 15:00 
GeneralRe: Count DataGridview row values and compare with an Array Pin
Andre Oosthuizen9-Aug-23 22:24
mveAndre Oosthuizen9-Aug-23 22:24 
SuggestionRe: Count DataGridview row values and compare with an Array Pin
Richard Deeming9-Aug-23 22:51
mveRichard Deeming9-Aug-23 22:51 
GeneralRe: Count DataGridview row values and compare with an Array Pin
Edilson Lemos 202110-Aug-23 7:44
Edilson Lemos 202110-Aug-23 7:44 
AnswerRe: Count DataGridview row values and compare with an Array Pin
Edilson Lemos 202110-Aug-23 17:23
Edilson Lemos 202110-Aug-23 17:23 
GeneralRe: Count DataGridview row values and compare with an Array Pin
Andre Oosthuizen11-Aug-23 0:15
mveAndre Oosthuizen11-Aug-23 0:15 
QuestionSharepoint Pin
Kevin Marois7-Aug-23 9:15
professionalKevin Marois7-Aug-23 9:15 
AnswerRe: Sharepoint Pin
Andre Oosthuizen8-Aug-23 0:15
mveAndre Oosthuizen8-Aug-23 0:15 
GeneralRe: Sharepoint Pin
Kevin Marois8-Aug-23 13:22
professionalKevin Marois8-Aug-23 13:22 
GeneralRe: Sharepoint Pin
Andre Oosthuizen8-Aug-23 23:22
mveAndre Oosthuizen8-Aug-23 23:22 
Question.NET 7 C# 8: using new Interface "features" ? Pin
BillWoodruff6-Aug-23 1:54
professionalBillWoodruff6-Aug-23 1:54 
AnswerRe: .NET 7 C# 8: using new Interface "features" ? Pin
Richard Andrew x646-Aug-23 7:14
professionalRichard Andrew x646-Aug-23 7:14 
GeneralRe: .NET 7 C# 8: using new Interface "features" ? Pin
BillWoodruff6-Aug-23 7:29
professionalBillWoodruff6-Aug-23 7:29 
GeneralRe: .NET 7 C# 8: using new Interface "features" ? Pin
trønderen6-Aug-23 11:03
trønderen6-Aug-23 11:03 
GeneralRe: .NET 7 C# 8: using new Interface "features" ? Pin
OriginalGriff6-Aug-23 12:09
mvaOriginalGriff6-Aug-23 12:09 

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.