c# - Best practice for nested using statements? -


I have a code block and I'm using 3 nested blocks

I found that using can finally use the blocks to avoid it, but if the statements are more than two using, then what is the best way is?

  Private file stream file stream = null; Private document document = null; Private PDFDriver pdfWriter = Faucet; Using {{FileSize = New Document (PageSize.A4, marginLeft, MarginRight, marginTop, marginBottom) using FileStream = New FileStream ("ABC.pdf", FileMode.Create)) {Using (pdfWriter = PdfWriter.GetInstance (document, fileStream) {document.AddAuthor (metaInformation ["author"]); document.AddCreator (metainformation ["creator"]); document.AddKeywords ("I report report using text"); Document.AddSubject ("Document Subject"); Document.AddTitle ("Document Title"); }}}}    

itemprop = "text">

you can remove nesting jagging By the way: using the file format (new fileStream ("ABC.pdf", FileMode.Create) (using FILEDocument = new document (PageSize.A4, using

  MarginLeft, marginRight, marginTop, marginBottom); (pdfWriter = PdfWriter.GetInstance (document, filestream)) {// code}   

Edit: As John Skeet Said, you should declare using the variable-statement

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -