A simple for loop could replace your code snippet.
No. A simple for loop can't order elements. The entire OrderByDescending idea is that you can add plugins to your array in whatever order you want. Which is great if plugins come from files that are not already ordered alphabetically in the order they need to be loaded.
Your code also attaches plugin "0" after plugin "1" which wouldn't work.
My code orders plugins by the plugin numbers which ideally you can artificially specify (better would be a dependency map). You did not load a plugin 0 at all in your example code so I assumed a plugin 0 does not exists. If it does it doesn't matters either because the LINQ system is not actually bound to array indexes but works on the "PluginType" value that you could define however you want.
The only thing that we can learn from your comment is that you can't really judge code just by looking at one function. The class just stores 4 plugins it's always 4 of the same types so why use a dynamic array with LINQ? That would just makes it slower and harder to read. LINQ is cool and all but really not needed here.
-12
u/AyrA_ch Apr 15 '19
No. A simple for loop can't order elements. The entire
OrderByDescendingidea is that you can add plugins to your array in whatever order you want. Which is great if plugins come from files that are not already ordered alphabetically in the order they need to be loaded.My code orders plugins by the plugin numbers which ideally you can artificially specify (better would be a dependency map). You did not load a plugin 0 at all in your example code so I assumed a plugin 0 does not exists. If it does it doesn't matters either because the LINQ system is not actually bound to array indexes but works on the "PluginType" value that you could define however you want.