0
Why can‘t .Sort() not be called via the Name of the Array? E.g. arrayName.Sort?
5 odpowiedzi
+ 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
+ 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]);
+ 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
+ 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 ^^
+ 1
Oh ok i didn‘t know that! Thank you so much sneeze !