有人對我有提示嗎? 我新的編碼:-)如何在下面的代碼中進行代碼重構?
private void PrintFile_btn_Click(object sender, EventArgs e)
{
PrintDocument printDoc = new PrintDocument();
PrintDocument printDoc2 = new PrintDocument();
List<PrintDocument> docList = new List<PrintDocument>();
printDoc.DocumentName = @"C:\Users\test\Desktop\1\1.pdf";
printDoc2.DocumentName = @"C:\Users\test\Desktop\1\2.pdf";
docList.Add(printDoc);
docList.Add(printDoc2);
printDoc.Print();
printDoc2.Print();
}
要多次打印同一文檔?只需使用for循環 –
不,我只是想打印一些文件。我發現這一點,它的工作原理。你能通過coderefactoring幫助我嗎? – Jannik153
爲什麼要創建一個列表?添加這些元素後不會使用它,因此它浪費線條,內存和時間。只要刪除第5,8,9行('List ...''docList.add ...''docList.add ...')。 –
Shirkam