I’m making a method to fetch a list of filenames from a server but I have come to a problem that I cannot answer.
The method returns two things:
- an
SftpResultwhich is an enum with a variety of return codes. - the list of filenames.
Of these three signatures:
public static ArrayList GetFileList(string directory, out SftpResult result)
public static SftpResult GetFileList(string directory, out ArrayList fileNames)
public static SftpFileListResult GetFileList(string directory)
(where SftpFileListResult is a composite object of an SftpResult and an ArrayList)
which is preferred and why?
Personally I prefer the last option (although using a
List<T>orReadOnlyCollection<T>instead ofArrayList).outparameters are basically a way of returning multiple values, and it’s generally nicer to encapsulate those.Another option in .NET 4 would be
That explicitly says, “this method returns two things… I’ve packed them together for you for this particular case, but it’s not worth further encapsulating them: they’re not worth composing in a separate type”.
(If you’re not using .NET 4 you could always write your own
Tupletype.)