1
複数の情報を返すために参照パラメータを使用しています。以下のように、C#参照パラメータの使用
int totalTransaction = 0;
int outTransaction = 0;
int totalRecord = 0;
var record = reports.GetTransactionReport(searchModel, out totalTransaction, out outTransaction, out totalRecord);
//および方法は、このようなものです
public List<TransactionReportModel> GetAllTransaction(
TransactionSearchModel searchModel,
out totalTransaction,
out totalTransaction,
out totalRecord) {
IQueryable<TransactionReportModel> result;
// search
return result.ToList();
}
しかし、私は長いパラメータを好きではないので、私は辞書を使用して、単一のパラメータとのことをクリーンアップしようとしています。
Dictionary<string, int> totalInfos = new Dictionary<string, int>
{
{ "totalTransaction", 0 },
{ "outTransaction", 0 },
{ "totalRecord", 0 }
};
var record = reports.GetTransactionReport(searchModel, out totalInfos);
しかし、キーストリングが約束されていないため、まだ十分ではないので、それは難しいコーディングのようです。
キーにConstantを使用する必要がありますか?そのような場合にはより良い解決法がありますか?
プロパティを使用してすべての情報を公開するクラスを作成するだけではどうですか。 –
これらの警告のすべてが重要ではありませんが、私はこれに同意します:https://msdn.microsoft.com/en-us/library/ms182131.aspx「out」パラメータが必要な理由を本当に理解していない限り、私は避けるでしょうそれら。 – starlight54