Usually by parameter (value type or reference type), and secondly, by return type.
If you have a method signature, such DateTime DateTime.AddDays(int days) , you get two hints that the method does not affect the original datetime - firstly, that DateTime is a value type, and secondly, it returns DateTime. Value types, if changed in the method body, will have their own changes applied locally to the copy on the stack. If the value type is not returned, the caller will not be able to make these changes. The types of links in contrast can be changed in the calling method and have changes observed by the caller.
Similarly, if you have a method like IOrderedEnumerable<T> OrderBy(IEnumerable<T> enumerable) , even though the input type is a reference type (and can be changed), the hint is that when you return a new type the original will remain unchanged.
Finally, this can be confirmed by testing. As a common point of interest, LINQ method chain extension methods return a new IEnumerable<T> , lazily evaluate and do not change the contents of the IEnumerable<T> passed in, instead using the filter that evaluates when GetEnumerator called, the IEnumerable<T>. returned IEnumerable<T>.
source share