Error. Too many characters in character literal

Lin100

Well-known member
Joined
Dec 12, 2022
Messages
69
Programming Experience
10+
Error - Too many characters in character literal:
private void DataGridView2_CellFormatting(object sender,
                          DataGridViewCellFormattingEventArgs e)
    {
        if (e.ColumnIndex == 8 & e.Value != null)
          {
             if (e.Value == '"Reserved"')                     <---- ERROR
                e.CellStyle.BackColor = Color.Yellow;
             else if (e.Value == '"Occupied"')              <---- ERROR
                e.CellStyle.BackColor = Color.Red;
             else if (e.Value == '"Occupied/Reserved"')    <---- ERROR
                e.CellStyle.BackColor = Color.OrangeRed;
             else if (e.Value == '"Vacant"')                   <---- ERROR
                e.CellStyle.BackColor = Color.Green;
           }
        }
 
Last edited by a moderator:
Error - Too many characters in character literal:
private void DataGridView2_CellFormatting(object sender,
                          DataGridViewCellFormattingEventArgs e)
    {
        if (e.ColumnIndex == 8 & e.Value != null)
          {
             if (e.Value == '"Reserved"')                     <---- ERROR
                e.CellStyle.BackColor = Color.Yellow;
             else if (e.Value == '"Occupied"')              <---- ERROR
                e.CellStyle.BackColor = Color.Red;
             else if (e.Value == '"Occupied/Reserved"')    <---- ERROR
                e.CellStyle.BackColor = Color.OrangeRed;
             else if (e.Value == '"Vacant"')                   <---- ERROR
                e.CellStyle.BackColor = Color.Green;
           }
        }
That's because in C# strings are in double quotes, and characters are in single quotes. You seem to be surrounding your strings with single quotes on the outermost layer, followed by double quotes the next layer in.
 
Last edited:
Back
Top Bottom