C# 如何使用泛型到PdfPcells
我正在使用iTextSharp生成表,我希望生成Pdfcells的泛型,而不是手动添加C# 如何使用泛型到PdfPcells,c#,asp.net,itextsharp,C#,Asp.net,Itextsharp,我正在使用iTextSharp生成表,我希望生成Pdfcells的泛型,而不是手动添加 PdfPCell HeadCell0 = new PdfPCell(new Paragraph("FullName", Htitle)); HeadCell0.BackgroundColor = Color.LIGHT_GRAY; PdfPCell HeadCell1 = new PdfPCell(new Paragraph("Username", Htitle)); HeadCell1.Background
PdfPCell HeadCell0 = new PdfPCell(new Paragraph("FullName", Htitle));
HeadCell0.BackgroundColor = Color.LIGHT_GRAY;
PdfPCell HeadCell1 = new PdfPCell(new Paragraph("Username", Htitle));
HeadCell1.BackgroundColor = Color.LIGHT_GRAY;
PdfPCell HeadCell2 = new PdfPCell(new Paragraph("Email", Htitle));
HeadCell2.BackgroundColor = Color.LIGHT_GRAY;
PdfPCell HeadCell3 = new PdfPCell(new Paragraph("Department", Htitle));
HeadCell3.BackgroundColor = Color.LIGHT_GRAY;
PdfPCell HeadCell4 = new PdfPCell(new Paragraph("AddedBy", Htitle));
HeadCell4.BackgroundColor = Color.LIGHT_GRAY;
PdfPCell HeadCell5 = new PdfPCell(new Paragraph("Account Type", Htitle));
HeadCell5.BackgroundColor = Color.LIGHT_GRAY;
如果@Alexis鸽子的评论不是您想要的,那么包装器函数呢
public static PdfPCell MakeHeader(string text, iTextSharp.text.Font Htitle) {
PdfPCell HeadCell = new PdfPCell(new Paragraph(text, Htitle));
HeadCell.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
return HeadCell;
}
PdfPCell HeadCell0 = MakeHeader("FullName", Htitle);
这就是您要找的吗?非常感谢,我的想法是将参数传递给生成循环的方法,并生成对象(如果得到我的想法但确实有用的方法:)