Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
for (int j = 0; j <= ttarray.Length; j++)
            {
                foreach(DataRow dr in dt.Rows)
                {
                    row++;

                    foreach(DataColumn dc in dt.Columns)
                    {
                        col++;

                        if ((dr["DayName"].ToString()==ttarray[j].DayName) && (dc.ColumnName == ttarray[j].HourName))
                        {

                            string FullName = ttarray[j].LastNameFaculity +" "+ttarray[j].FirstNameFaculity;
                            string week;

                            dt.Rows[row][col] = FullName + ttarray[j].LessonName + week;
                        }
                    }

                }

            }

warning : Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string' (dr["DayName"].ToString()==ttarray[j].DayName)
Posted

1 solution

I can't see a good reason for that error, but I'd try moving the code about a bit:
C#
for (int j = 0; j <= ttarray.Length; j++)
{
    foreach(DataRow dr in dt.Rows)
    {
        row++;
        string dayName = dr["DayName"].ToString();

        foreach(DataColumn dc in dt.Columns)
        {
            col++;

            if ((dayName==ttarray[j].DayName) && (dc.ColumnName == ttarray[j].HourName))
            {

                string FullName = ttarray[j].LastNameFaculity +" "+ttarray[j].FirstNameFaculity;
                string week;

                dt.Rows[row][col] = FullName + ttarray[j].LessonName + week;
            }
        }

    }
I'd probably also extract the ttarray[j] to a named class instance:
C#
MyClass whateverThisIsSupposedToBe = ttarray[j];
And use the name throughout instead. (The optimiser will probably do that for you, but it makes the code a little more readable)

That may remove the error.

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900