0

Why can‘t .Sort() not be called via the Name of the Array? E.g. arrayName.Sort?

8th Jun 2021, 9:04 AM
Marvin
5 Antworten
+ 3
No sum is a extension method of linq. This is the power of extension methods. It look like, it is a class method but it is not. comment out using linq in the code below. You will see that sum is no longer a part of the array class https://code.sololearn.com/cO4oym2R0Wl3/?ref=app https://www.csharp-examples.net/linq-sum/ https://www.tutorialsteacher.com/csharp/csharp-extension-method
8th Jun 2021, 11:19 AM
sneeze
sneeze - avatar
+ 4
Marvin Because Sort() is a static method of Array class which needs one parameter as an array to sort array like this: int[] arr = {1, 5, 4, 6}; Array.Sort(arr); for (int i = 0; i < 4; i++) Console.Write(arr[i]);
8th Jun 2021, 9:10 AM
A͢J
A͢J - avatar
+ 2
Marvin No Sum() is not a method of Array class. You can see here which method exist in Array class. https://docs.microsoft.com/en-us/dotnet/api/system.array?view=net-5.0
8th Jun 2021, 3:42 PM
A͢J
A͢J - avatar
+ 1
Thanks but it still don‘t get it: .Sum() is a static method of Array class as well, right? Why can i call it via the Name of the Array? Sorry if that is a stupid question ^^
8th Jun 2021, 9:35 AM
Marvin
+ 1
Oh ok i didn‘t know that! Thank you so much sneeze !
8th Jun 2021, 1:45 PM
Marvin