2

メソッドの戻り値としてaList<T>と a の両方を渡す最良の方法は何ですか? bool現在、コンテナのように振る舞うというカスタムクラスBoolListがありますが、それを行うためのより良い方法やよりエレガントな方法があるかどうか疑問に思っていました。

4

3 に答える 3

4

タプルを使用しないのはなぜですか?

http://www.dotnetperls.com/tuple

http://msdn.microsoft.com/en-us/library/dd268536.aspx

次に、クラスを作成しなくても、タイプ セーフなコンテナーを作成できます。

    private Tuple<List<int>, bool> myMethod()
    {
        var myList = new List<int>();
        var myBool = true;

        return new Tuple<List<int>, bool>(myList, myBool);
    }
于 2013-09-11T09:52:16.927 に答える
3

使用できますTuple<List<T>, bool>

public Tuple<List<string>, bool> MethodName()
{
    return Tuple.Create(new List<string>(), true);
}

またはList<T> outパラメータを作成し、bool通常のものとして返します(TryParseメソッドのように)

public bool MethodName(out List<string> results)
{
    results = new List<string>();
    return true;
}
于 2013-09-11T09:52:52.487 に答える