Best practice for nested using statements?

后端 未结 5 994
情书的邮戳
情书的邮戳 2021-01-17 12:19

I have a code block as follows and I\'m using 3 nested using blocks.

I found that using try finally blocks I can avoid this but if there a

5条回答
  •  感情败类
    2021-01-17 13:08

    You can remove the indention and curly brackets this way:

    using (var fileStream = new FileStream("ABC.pdf", FileMode.Create))
    using (var document = new Document(PageSize.A4, marginLeft, marginRight, marginTop, marginBottom))
    using (var pdfWriter = PdfWriter.GetInstance(document, fileStream))
    {
       // code
    }
    

提交回复
热议问题