Unconditional recursion (ARCH717)
هذا المحتوى غير متوفر بلغتك بعد.
Key dotnet.codequality.unconditional-recursion · Severity critical · Category codequality
Flags a method that calls itself, or a property getter that reads itself, on every path: nothing before the call can return, throw or branch away, so the recursion never ends and the process dies with a stack overflow.
Recursion is normal code when it has a way out. A call inside an if, a loop, a switch, a try or a lambda, or behind ?:, &&, ||, ?? or ?., is not reported. Neither is a call to another overload or to base. A setter that assigns itself is Infinite recursion (CA2011).
Incorrect
Section titled “Incorrect”public string Name => Name;
public int Sum(int n){ var doubled = n * 2; return Sum(doubled);}Correct
Section titled “Correct”private string _name = "";public string Name => _name;
public int Sum(int n){ if (n <= 0) return 0; return n + Sum(n - 1);}