Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Burichan 17 posts 129 karma points
    Aug 25, 2017 @ 09:19

    Hi guys, later this morning I was trying to write down the following loop using a variable named "event".

    @foreach (var event in myEvents) { 

    All I got was an error message from the compiler stating that it was expecting a '}'. Does the word "event" act as a keyword? Because after renaming it, everything worked fine.


  • Dave Woestenborghs 3252 posts 11032 karma points MVP 5x admin c-trib
    Aug 25, 2017 @ 09:42
    Dave Woestenborghs

    Hi Burichan,

    I think this beause event is a reserved word in .NET

    Maybe you can try @@eventt.GetPropertValue("title") or @(event.GetPropertValue("title"))

    That should fix it.


  • Burichan 17 posts 129 karma points
    Aug 25, 2017 @ 09:54

    Hmm, double '@' sign? Never came up with a syntax like this before. Compiler still doesn't let me use the word "event", but it's alright. I can live w/o it. But it felt strange due to the "expecting {" message. It convinced me I was blind for a second... Hahaha!

  • Dan Diplo 1490 posts 5809 karma points MVP 4x c-trib
    Aug 25, 2017 @ 10:28
    Dan Diplo

    Yes, "event" is a reserved keyword in C#. Whilst you can work around it - like Dave says - you'd be best to avoid using any of these are variable names to avoid cofusion:

Please Sign in or register to post replies

Write your reply to: