Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Any language supports this type of syntax?

Any language supports this type of syntax?

Scheduled Pinned Locked Moved The Lounge
question
20 Posts 12 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Eytukan

    int nThatVeryLongVariableYourMateNamed = 0;

    if(nThatVeryLongVariableYourMateNamed != (0,1,2))
    {
    //Do something
    }

    Instead of having to do like:

    int nThatVeryLongVariableYourMateNamed = 0;

    if(nThatVeryLongVariableYourMateNamed != 0 &&
    nThatVeryLongVariableYourMateNamed != 1 &&
    nThatVeryLongVariableYourMateNamed != 2
    )
    {
    //Do something
    }

    -VUNIC

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #11

    {
    int localVLVYMN = thatVeryLongVariableYourMateNamed;
    }

    As a single block, so that your temp-int is limited in scope. Also spitting on the hungarian notation - I would not tough that code with a polearm :thumbsup:

    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

    Richard DeemingR 1 Reply Last reply
    0
    • L Lost User

      {
      int localVLVYMN = thatVeryLongVariableYourMateNamed;
      }

      As a single block, so that your temp-int is limited in scope. Also spitting on the hungarian notation - I would not tough that code with a polearm :thumbsup:

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #12

      For extra C#7 goodness:

      {
      ref int localVLVYMN = ref thatVeryLongVariableYourMateNamed;
      ...
      }

      Now any changes to your alias will be reflected in the original. :) An added benefit for large structs: you avoid making a copy of the value. Ref return values and ref locals (C# Guide) | Microsoft Docs[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      L 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        For extra C#7 goodness:

        {
        ref int localVLVYMN = ref thatVeryLongVariableYourMateNamed;
        ...
        }

        Now any changes to your alias will be reflected in the original. :) An added benefit for large structs: you avoid making a copy of the value. Ref return values and ref locals (C# Guide) | Microsoft Docs[^]


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #13

        Richard Deeming wrote:

        Now any changes to your alias will be reflected in the original. :)

        More ways to obfuscate my code :-D

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

        Richard DeemingR 1 Reply Last reply
        0
        • L Lost User

          Richard Deeming wrote:

          Now any changes to your alias will be reflected in the original. :)

          More ways to obfuscate my code :-D

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #14

          More job security. :-D


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          L 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            More job security. :-D


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #15

            Can't argue with that :)

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

            1 Reply Last reply
            0
            • E Eytukan

              int nThatVeryLongVariableYourMateNamed = 0;

              if(nThatVeryLongVariableYourMateNamed != (0,1,2))
              {
              //Do something
              }

              Instead of having to do like:

              int nThatVeryLongVariableYourMateNamed = 0;

              if(nThatVeryLongVariableYourMateNamed != 0 &&
              nThatVeryLongVariableYourMateNamed != 1 &&
              nThatVeryLongVariableYourMateNamed != 2
              )
              {
              //Do something
              }

              -VUNIC

              J Offline
              J Offline
              Joan M
              wrote on last edited by
              #16

              Wasn't the old visual basic capable to use WITH?

              www.robotecnik.com[^] - robots, CNC and PLC programming

              E 1 Reply Last reply
              0
              • J Joan M

                Wasn't the old visual basic capable to use WITH?

                www.robotecnik.com[^] - robots, CNC and PLC programming

                E Offline
                E Offline
                Eytukan
                wrote on last edited by
                #17

                You remember the syntax? :)

                Full Reset

                1 Reply Last reply
                0
                • E Eytukan

                  int nThatVeryLongVariableYourMateNamed = 0;

                  if(nThatVeryLongVariableYourMateNamed != (0,1,2))
                  {
                  //Do something
                  }

                  Instead of having to do like:

                  int nThatVeryLongVariableYourMateNamed = 0;

                  if(nThatVeryLongVariableYourMateNamed != 0 &&
                  nThatVeryLongVariableYourMateNamed != 1 &&
                  nThatVeryLongVariableYourMateNamed != 2
                  )
                  {
                  //Do something
                  }

                  -VUNIC

                  D Offline
                  D Offline
                  DaveAuld
                  wrote on last edited by
                  #18

                  In Python you can use range(). So, for [0,1,2] you would do either;

                  if nThatVeryLongVariableYourMateNamed not in [0,1,2]:

                  or

                  if nThatVeryLongVariableYourMateNamed not in range(3):

                  or

                  if nThatVeryLongVariableYourMateNamed not in range(0,3):

                  or

                  if nThatVeryLongVariableYourMateNamed not in range(0,3,1):

                  Dave Find Me On:Web|Youtube|Facebook|Twitter|LinkedIn Folding Stats: Team CodeProject

                  E 1 Reply Last reply
                  0
                  • D DaveAuld

                    In Python you can use range(). So, for [0,1,2] you would do either;

                    if nThatVeryLongVariableYourMateNamed not in [0,1,2]:

                    or

                    if nThatVeryLongVariableYourMateNamed not in range(3):

                    or

                    if nThatVeryLongVariableYourMateNamed not in range(0,3):

                    or

                    if nThatVeryLongVariableYourMateNamed not in range(0,3,1):

                    Dave Find Me On:Web|Youtube|Facebook|Twitter|LinkedIn Folding Stats: Team CodeProject

                    E Offline
                    E Offline
                    Eytukan
                    wrote on last edited by
                    #19

                    Cool :thumbsup:

                    Full Reset

                    1 Reply Last reply
                    0
                    • P Pete OHanlon

                      You could do that as an extension method in C# pretty easily. The syntax would be something like ```csharp if (nThatVeryLongVariableYourMateNamed.Excludes(0,1,2)) ```

                      This space for rent

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #20

                      Copy paste from SOverflow

                      static class Extensions
                      {

                      public static bool In(this T item, params T\[\] items)
                      {
                          if (items == null)
                              throw new ArgumentNullException("items");
                      
                          return items.Contains(item);
                      }
                      

                      }

                      class Program
                      {

                      static void Main()
                      {
                      
                      
                          int myValue = 1;
                      
                          if (myValue.In(1, 2, 3))
                              // Do Somthing...
                      
                          string ds = "Bob";
                      
                          if (ds.In("andy", "joel", "matt")) 
                          // Do Someting...
                      }
                      

                      }

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups