TheAlgorithms / C-Sharp

All algorithms implemented in C#.
GNU General Public License v3.0
6.94k stars 1.49k forks source link

(Fix IDE0180) Favor modern tuple swap over temporary variables. #401

Closed Captain-Quack closed 11 months ago

Captain-Quack commented 11 months ago

C# 7 brought tuple types, which allowed for very clean and efficient swapping of values. This pull request replaces temporary variable assignments across the repository with said feature:

// === Example ===
// before:
int temp = numbers[0];
numbers[0] = numbers[1];
numbers[1] = temp;
// after
(numbers[1], numbers[0]) = (numbers[0], numbers[1]);

See more details on the code issue here.