-2

I ran a static code analysis tool on our tool and looking at its results the code below was one of the things it was talking about:

    SpreadSnapshot oSnap = new SpreadSnapshot();
    using (oSnap.SetRowCol(fpSpread, row, col))
    {
        SpreadSetComboBox(fpSpread, list, displayProperty);
    }

So I changed it to the code below and it fixed the error that the tool was talking about:

    using (SpreadSnapshot oSnap = new SpreadSnapshot())
    {
        oSnap.SetRowCol(fpSpread, row, col);
        SpreadSetComboBox(fpSpread, list, displayProperty);
    }

So in your opinion Which style of coding do you think is more appropriate and less error-prone?

Thanks

4

2 に答える 2

6

後者 -ステートメントのoSnap に使用しないようにします。using

それはさておき、使い捨てのものを返品するのはかなり奇妙ですSetRowCol...それはどういう意味ですか?

于 2012-02-09T21:31:14.647 に答える
4

SetRowCol最後に返さない限り、この2つはまったく異なることを意味しますthis。最初に、 の結果を破棄していますSetRowCol。2 番目では、SpreadSnapshot.

両方が使い捨ての場合は、両方に対して using を実行する必要があります。

using (SpreadSnapshot oSnap = new SpreadSnapshot())
using (oSnap.SetRowCol(fpSpread, row, col))
{
    SpreadSetComboBox(fpSpread, list, displayProperty);
}
于 2012-02-09T21:32:42.710 に答える