trying out the prototype

Serge Boulay serge.boulay at gmail.com
Tue Aug 24 06:40:52 PDT 2010


The "using" block in c# only allows one resource unless the resources are of
the same type. To use multiple resources they are nested or stacked

using (StreamWriter w1 = File.CreateText("W1"))
using (StreamWriter w2 = File.CreateText("W2"))
{
      // code here
}

instead of

using (StreamWriter w1 = File.CreateText("W1"))
  {
      using (StreamWriter w2 = File.CreateText("W2"))
      {
          // code here
      }
   }

Depending on the number of resources, the "using" block nesting can quickly
get out of hand.





On 8/24/10, Stephen Colebourne <scolebourne at joda.org> wrote:
>
> On 24 August 2010 12:14, David Holmes <David.Holmes at oracle.com> wrote:
> >> (I guess this forms a case against the try-with-multiple-resources
> >> statement in general. The list of semicolon-delimited declarations
> >> enclosed by parentheses looks weird, anyway ;-)
> >
> > I tend to agree the syntax is awkward and far less readable than simply
> > nesting the try-with statements.
>
> Overall, I think the semicolon, multi-resource, aspect is more complex
> than the benefits it gives. Clearer code results from nesting the
> statements.
>
> Stephen
>
>



More information about the coin-dev mailing list