Returning information about the result of a file processing, without using output parameters As part of a C# class CsvConverter that converts various file types to CSV, I am designing a private class CsvConversionResult. My current design choice is to return a null value of CsvConversionResult if processing is successful.

What can I add to or remove from my design to use "best practices"? Returning primitive data types is out of the question since I want to return more than one thing.

public static class CsvConverter
{
    public class CsvConverterError
    {  
        public string Message { get; set; }
        public int LineNumber { get; set; }
        public string FileName { get; set; }

        public CsvConverterError(string message, int lineNumber, string fileName)
        {
            Message = message;
            LineNumber = lineNumber;
            FileName = fileName;
        }
    }

    // returns null if successful
    public static CsvConverterError WriteCsvRowsToFile(char delimiter, 
                                                 string inputFilePath, 
                                                 string outputFilePath, 
                                                 string qualifier = "")
    {
        CsvConverterError error = null;

        /* Some code here that sets the value of error accordingly */

        return error;
    }
As one of the commenters pointed out, adding a boolean flag to your result is one of the better ways to go about returning a successful result, especially when compared to returning null. In fact, I have a wrapper around a search result object where I do exactly this in the code for my current project. 


  "null" makes me think of "something wrong". 


This is exactly why null should not be used for this situation. At worst you'll have a programmer later who is totally confused about what is going on in your code, as most people will not return null from a function, especially for successful completion of that code. 

This is the code I use: 

public class SearchMemberEligibilityWrapper
{
    public List&lt;RegularMember&gt; ResultList { get; set; }
    public int ResultCount { get; set; }
    public bool ResultSuccessful { get; set; }
    public SearchType ResultSource { get; set; }
    public string ResultError { get; set; }

    public SearchMemberEligibilityWrapper()
    {
        this.ResultList = new List&lt;RegularMember&gt;();
        this.ResultCount = 0;
        this.ResultSuccessful = false;
        this.ResultSource = SearchType.Default;
        this.ResultError = string.Empty;
    }

    public enum SearchType
    {
        Default,
        QNXT,
        Database,
        Historical
    }
}


Then the code that uses the SearchMemberEligibilityWrapper checks for the value of ResultSuccessful to decide what to do after the search attempt. You have three states that the search result can exist in:


Search unsuccessful (error)
Search successful, 0 results
Search successful, >0 results


If you're concerned about having multiple errors per file, then using this pattern you can even have a List&lt;string&gt; property for your errors, and list your errors individually, rather than simply having one error for everything.