Hi guys, later this morning I was trying to write down the following loop using a variable named "event".
@foreach (var event in myEvents) {
<span>@event.GetPropertyValue("title")</span>
}
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.
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!
What's wrong with @event?
Hi guys, later this morning I was trying to write down the following loop using a variable named "event".
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.
Peace.
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.
Dave
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!
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: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/index
is working on a reply...