Let's say I have a method foothat returns a ValueTuple, where one of its members is one-time, for example (IDisposable, int).
foo
ValueTuple
(IDisposable, int)
What is the best way to ensure that the returned disposable object is correctly placed on the caller?
I tried the following:
using (var (disposable, number) = foo()) { // do some stuff using disposable and number }
But this does not compile:
'(IDisposable disposable, int number)': the type used in the using statement must be implicitly converted to 'System.IDisposable'
Do I need to wrap my code in a try-finally block and explicitly delete my object in a finally block, or is there a better way to do this?
, , ValueTuples IDisposable Dispose() . Microsoft?
IDisposable
Dispose()
using, :
using
var (disposable, number) = foo(); using (disposable) { // do some stuff using disposable and number }
, , - , using , . . , using , .
. , , ( ?!?!). , , .
, , , , .
. , , , . . , , : , , , , , - , .
Source: https://habr.com/ru/post/1686416/More articles:Algorithms Count all pairs of equal numbers in a sorted array in O (n)? - javaInserting data in MySQL db in all tables - databasehttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1686413/layout-issues-after-updates-to-x-code-9&usg=ALkJrhj9Dr9Rehnm7ptSIGV6O2xFCPNzvwAndroid application for unity based on native OpenCV - c ++Why does javafx control my translucent cursors? - javaPrinting char data type with printf () - cOptimization of aggregated query for a large data set - optimizationAndroid Firebase Dynamic Links Not Working In Facebook Messenger Correctly - androidHow to disable previous items in ListView - androidVSTS - NuGet version using AssemblyInfo and assembly extension - nugetAll Articles