-2

i am still learning c# and .net core. Some time ago one guy send to me a exercise on which unfortunately i fall off mainly because of this function definition :

public static (int UserId, decimal MaximumTotalInstallment)[] Process(User[] users) {}

This is a library function which is used in XUnit test class in another namespace :

var expected = new[] {(1, 100m), (2, 1000m)};
        
// when
var output = BatchProcessingLibraryClass.Process(input);
        
// then
output.Should().BeEquivalentTo(expected);

Could You please tell me what this call of lib function exactly do ? I dont meet this kind of function declaration before.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Bartosz
  • 35
  • 4
  • `(int UserId, decimal MaximumTotalInstallment)` is named *tuple* which contains two properties: `int UserId` and `decimal MaximumTotalInstallment`. Then when adding `[]` we have *array* of named tuples: `(int UserId, decimal MaximumTotalInstallment)[]`. I hope that `User[] users` is clear: array of `User` – Dmitry Bychenko Apr 10 '21 at 19:03

1 Answers1

1

You cannot tell what it does from the name (other than "process"), but you can tell what inputs are expected and what outputs are produced

  • Inputs - An array of User type called users.
  • Output - An array of a tuple. This tuple has two fields an integer named UserId and a decimal named MaximumTotalInstallment. This type is equivalent to ValueTuple<int,decimal>.

Other notes, the method is static which means it is called not for a particular instance of a class, but callable (like a library) from anywhere else.

John Alexiou
  • 28,472
  • 11
  • 77
  • 133