I have a C# function that does some processing and needs to return figures about what it has processed, success, failure, etc.
Can anyone tell me if there are any standard framework classes that will handle this (for example, number of records processed, number successful, failed, etc) ?
Alternatively, can anyone say how they usually handle this? Is the best way to create a class, or to use out parameters?
I don’t think there is any standard class for representing this kind of information. The best way to handle this is probably to define your own class. In C# 3.0, you can use automatically implemented properties, which reduce the amount of code you need to write:
I think
outparameters should be used only in relatively limited scenarios such as when defining methods similar toInt32.TryParseand similar.Alternatively, if you need to use this only locally (e.g. call the function from only one place, so it is not worth declaring a new class to hold the results), you could use the
Tuple<..>class in .NET 4.0. It allows you to group values of several different types. For exampleTuple<double, double, double>would have propertiesItem1…Item3of typesdoublethat you can use to store individual results (this will make the code less readable, so that’s why it is useable only locally).