none
Too many characters in character literal RRS feed

  • Question

  • Can someone please explain to me the following:

    I have this LinqToSqlquery which works perfectly:
    var currencylist = from fields in DataCont.Currencies select new {CodeName = fields.Code  + '-' + fields.Description , fields.ID };

    The moment I change the "-" between the Code and description fields eg. " - ", I get the "Too many characters in character literal" error during compile time:
    var currencylist = from fields in DataCont.Currencies select new {CodeName = fields.Code  + ' - ' + fields.Description , fields.ID };

    It does not make sense and I was unable to find an answer/solution yet.

    Thanks so much.

    Wednesday, June 3, 2009 10:14 AM

Answers

  • Thanks so much Martin, I can't believe I missed something so obvious, it must have been late nights and the fact that the '-' worked and that I was working the whole day with T-SQL statements.
    • Marked as answer by Anton Marais Wednesday, June 3, 2009 12:14 PM
    Wednesday, June 3, 2009 12:13 PM

All replies

  • String literals in C# are delimited by double quotes so you need to use " - " not ' - ':
    var currencylist = from fields in DataCont.Currencies select new {CodeName = fields.Code  + " - " + fields.Description , fields.ID };

    MVP XML My blog
    • Proposed as answer by CetinBasoz Wednesday, June 3, 2009 12:06 PM
    • Marked as answer by Anton Marais Wednesday, June 3, 2009 12:11 PM
    • Unmarked as answer by Anton Marais Wednesday, June 3, 2009 12:11 PM
    Wednesday, June 3, 2009 12:02 PM
  • Thanks so much Martin, I can't believe I missed something so obvious, it must have been late nights and the fact that the '-' worked and that I was working the whole day with T-SQL statements.
    • Marked as answer by Anton Marais Wednesday, June 3, 2009 12:14 PM
    Wednesday, June 3, 2009 12:13 PM