gpt4 book ai didi

c# - 默认参数 PageSize A4 C# 使用 itextsharp

转载 作者:太空狗 更新时间:2023-10-30 01:06:30 25 4
gpt4 key购买 nike

是否可以在 C# 中为 PageSize 的默认参数设置值?例如:

public virtual void Render(string reportTitle, Rectangle pageSize = PageSize.A4)
{
foreach (Page p in pages)
{
p.Render(document);
document.NewPage();
document.AddCreationDate();
document.AddTitle(reportTitle);
document.SetPageSize(pageSize);
}
}

我在 Visual Studio 2010 中出现以下错误:

Default parameter value for 'pageSize' must be a compile-time constant.

最佳答案

当你写的时候;

Rectangle pageSize = PageSize.A4

您的 pageSize 值可以作为参数更改。

来自 Named and Optional Arguments

A default value must be one of the following types of expressions:

  • a constant expression;

  • an expression of the form new ValType(), where ValType is a value type, such as an enum or a struct;

  • an expression of the form default(ValType), where ValType is a value type.

表达式 PageSize.A4 未归类为 compile-time constant .

关于c# - 默认参数 PageSize A4 C# 使用 itextsharp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15365416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com