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. General Programming
  3. C#
  4. How to create a recursive lambda function ?

How to create a recursive lambda function ?

Scheduled Pinned Locked Moved C#
tutorialcsharplinqfunctionalquestion
6 Posts 4 Posters 0 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.
  • J Offline
    J Offline
    Jesus Carroll
    wrote on last edited by
    #1

    Hi: How to define a recursive lambda function using C#? By example, I was using the following sentence to get the even numbers in a Real group: double[] doubles = Odd(a, (double x) => x + 2.0); Any ideas? :^)

    Ieshua Carroll Systems Engineer

    L J Richard DeemingR 3 Replies Last reply
    0
    • J Jesus Carroll

      Hi: How to define a recursive lambda function using C#? By example, I was using the following sentence to get the even numbers in a Real group: double[] doubles = Odd(a, (double x) => x + 2.0); Any ideas? :^)

      Ieshua Carroll Systems Engineer

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

      Try Anonymous Recursion in C# – Yet Another Language Geek[^] :)

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      J 1 Reply Last reply
      0
      • L Lost User

        Try Anonymous Recursion in C# – Yet Another Language Geek[^] :)

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        J Offline
        J Offline
        Jesus Carroll
        wrote on last edited by
        #3

        ;) It is an useful link. Thanks !

        L 1 Reply Last reply
        0
        • J Jesus Carroll

          ;) It is an useful link. Thanks !

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

          yw :)

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          1 Reply Last reply
          0
          • J Jesus Carroll

            Hi: How to define a recursive lambda function using C#? By example, I was using the following sentence to get the even numbers in a Real group: double[] doubles = Odd(a, (double x) => x + 2.0); Any ideas? :^)

            Ieshua Carroll Systems Engineer

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            However one should read the following and understand it. StackOverflowException Class (System)[^] Especially understand that it will terminate the AppDomain absolutely. And read the following... "if your app depends on recursion, use a counter or a state condition to terminate the recursive loop. The following example uses a counter to ensure that the number of recursive calls to the Execute method do not exceed a maximum defined by the MAX_RECURSIVE_CALLS constant. "

            1 Reply Last reply
            0
            • J Jesus Carroll

              Hi: How to define a recursive lambda function using C#? By example, I was using the following sentence to get the even numbers in a Real group: double[] doubles = Odd(a, (double x) => x + 2.0); Any ideas? :^)

              Ieshua Carroll Systems Engineer

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

              If you're using a recent version of the C# compiler, you might want to consider local functions: Local functions (C# Programming Guide) | Microsoft Docs[^] Using the function from the blog post that Eddy linked to, it works almost without change:

              int Fib(int n) => n > 1 ? Fib(n - 1) + Fib(n - 2) : n;
              Console.WriteLine(Fib(6)); // displays 8

              (Of course, the best solution for calculating Fibonacci numbers is to avoid recursion. :) )


              "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

              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