calculating the index of an array C#
        Posted  
        
            by 
                Kerry G
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Kerry G
        
        
        
        Published on 2012-10-14T09:31:18Z
        Indexed on 
            2012/10/14
            9:37 UTC
        
        
        Read the original article
        Hit count: 274
        
I want to display a list of the answers a student entered incorrectly. How do I identify the index of these questions?
I am hoping to change the contents of a textbox to a list of the questions answered incorrectly, which would require calculating the index of each incorrect question.
using System; 
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //return a pass/fail
        //return number of correct answers
        //return number of incorrect answers
        //return index figures of incorrect values
        public void examResults ()
        {
            string[] correctAnswers = {B,D,A,A,C,A,B,A,C,D,B,C,D,A,D,C,C,B,D,A}; 
            string[] studentResults = File.ReadAllLines("studentResults.txt");
            var c = correctAnswers.Where((x, i) => x.Equals(studentResults[i])).Count();
            if ( c <= 14)
                passFailBox.Text = "Student has failed the exam";
            else
                passFailBox.Text = "Student has passed the exam";
            numberCorrectBox.Text = "Student has answered" + c + "answers correctly";
            int f; 
            f= 21-c;
            numberIncorrectBox.Text = "Student has answered" + f + "answers incorrectly";
        }
    }
}
© Stack Overflow or respective owner