0

I'm seeing this very often recently - what does it mean?

public void IPersistenceRepository<TEntity> : IDisposable {

                                                                      | 
                                                                      v
    public IEnumerable<TEntity> Where(Expression<Func<TEntity, bool>> @predicate);

}

or

public IDomainEventHandler<TEvent> : IEventHandler {

                              | 
                              v
    public void Handle(TEvent @event);

}
Acrotygma
  • 2,531
  • 3
  • 27
  • 54

2 Answers2

5

From the C# Language Specification, § 2.4.2 Identifiers (C#) :

The prefix "@" enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An identifier with an @ prefix is called a verbatim identifier.

Its a method of escaping identifiers which are also keywords.

Community
  • 1
  • 1
Sadique
  • 22,572
  • 7
  • 65
  • 91
0

It's just part of the variable name, but allows you to use reserved key words of the C# language, as names and identifiers.

This has to do with that that the .Net framework designed not for specific language. What would happen if code that was written in other .Net language would use C#'s reserved key word as an identifier name? How can use access that identifier from C#? the answer is that you would add @ before the parameter name.

You can use this feature regardless of using code from other languages (as in your code, you define a variable called event although event is reserved key word), and even regardless of using key words (predicate is not a key word, yet, you can still prefix it with @).

Shlomi Borovitz
  • 1,700
  • 9
  • 9