1

I'm using reference parameter for returning multiple information. like,

int totalTransaction = 0;
int outTransaction = 0;
int totalRecord = 0;

var record = reports.GetTransactionReport(searchModel, out totalTransaction, out outTransaction, out totalRecord);

// and the method is like this,

public List<TransactionReportModel> GetAllTransaction(
            TransactionSearchModel searchModel, 
            out totalTransaction,
            out totalTransaction,
            out totalRecord) {


    IQueryable<TransactionReportModel> result;
    // search

    return result.ToList();
}

But I don't like the long parameters, so I'm trying to cleaning that up with single parameter, using Dictionary.

Dictionary<string, int> totalInfos = new Dictionary<string, int>
{
    { "totalTransaction", 0 },
    { "outTransaction", 0 },
    { "totalRecord", 0 }
};

var record = reports.GetTransactionReport(searchModel, out totalInfos);

But still not good enough, because the key strings are not promised, it's like hard cording.

Do I need to use Constant for the keys? or any better solution for that case?

1
  • 1
    Although not all of these warnings matter, I do agree with this one: msdn.microsoft.com/en-us/library/ms182131.aspx Unless you really understand why you need an out parameter I would avoid them. Commented Jul 30, 2016 at 15:15

1 Answer 1

5

Just use a class. And avoid out parameters completely:

class TransactionResult
{
    public List<TransactionReportModel> Items { get; set; }

    public int TotalTransaction { get; set; }
    public int OutTransaction { get; set; }
    public int TotalRecord { get; set; }
}


public TransactionResult GetAllTransaction(TransactionSearchModel searchModel)
{
    IQueryable<TransactionReportModel> result;
    // search

    return new TransactionResult
    { 
        Items = result.ToList(),
        TotalTransaction = ...,
        OutTransaction = ...,
        TotalRecord = ...
    };
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.