Quantcast
Channel: Planet Object Pascal
Viewing all articles
Browse latest Browse all 1725

The Wiert Corner - irregular stream of stuff: jpluimers

$
0
0

Normally you would not want to use a reserved word as an identifier. But sometimes it can be very convenient, for instance for a code generator that wraps remoting calls or does ORM.

Both Delphi and C# have an escape for this:

The prefixes are to tell the compiler knows you really know what you are doing, and are using a reserved word as an identifier.

The cool thing: in the Run Time Type Information (Delphi) or Reflection (C# and VB.NET) you will see the names without the prefix.

Some examples from StackOverflow:

& prefix for Delphi

private &string: Integer;

Kenny Cason answered delphi – Is it possible to use reserved words for field names? – Stack Overflow.

@ prefix for C#

private long @string;

Jon Skeet answered Use the long reserved word as a variable name in C# – Stack Overflow.

[] embedding for VB.NET

Private [string] As Integer;

Tobias Wittenburg asked vb.net – Reserved Keyword in Enumeration in C# – Stack Overflow.

The VB.NET way also works in Microsoft SQL Server and Microsoft Access.

“” embedding in many SQL syntaxes

Examples:

Exception: Microsoft SQL Server and Microsoft Access use [] embedding.

Note:

Some SQL implementations uses the embedding not only to allow for reserved words, but also to allow embedding spaces in identifiers.

Delphi, C# and VB.NET cannot do that, so be aware of that when performing ORM work.

–jeroen


Filed under: .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Delphi, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 8, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Development, Software Development, VB.NET, VB.NET 10.0, VB.NET 11.0, VB.NET 7.0, VB.NET 7.1, VB.NET 8.0, VB.NET 9.0

Viewing all articles
Browse latest Browse all 1725

Trending Articles