Not 'if', but '@if'

This is a discussion on Not 'if', but '@if' within the C# Programming forums, part of the General Programming Boards category; Heres a little C# trivia for you. Did you know, while you can't declare variabls/members/methods with the same names as ...

  1. #1
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986

    Not 'if', but '@if'

    Heres a little C# trivia for you. Did you know, while you can't declare variabls/members/methods with the same names as C# keywords (if, while, try etc), you can if you prefix them with an @ (@if, @while, @try @etc).

    http://msdn.microsoft.com/library/de...eywords_PG.asp

  2. #2
    Registered User
    Join Date
    May 2005
    Posts
    28
    The better question is why would you want to?



    Mezzano

  3. #3
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    A good question. Thanks to English a lot of the names for keywords are only really useful for keywords. They don't describe anything at all useful in classes or data types.

  4. #4
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    We had a use the other day. VB.NET uses the Me keyword rather than 'this' (the justification for this is "VB PROGRAMMERS ARE STUPID"). We write C# code, which is called by our clients in a little scripting language which is really just VB.NET when we inject into a class definition and run against our business layer. Anyway, we wanted them to use the This keyword to access a business object their script was running on. So in C# we called the property @this. If we had uses just this, the code wouldn't have compiled in C#.

    I don't think we got so far as testing it though, since we realised we could call it 'This' and avoid the same problems ('coz VB.NET is case stupid). But in theory I think it would work.

    So in summary, I don't care whether you use it or not, and I doubt anyone ever will, I was just pointing out it's there. So there.

  5. #5
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Well it is a good thing to know. Thanks for pointing it out.

    Oh and when it comes to case problems... yeah VB has to be different.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21