PageSize A4 C # default setting using itextsharp

Is it possible to set default values ​​for PageSize in C #? For instance:

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); } } 

I have the following error in Visual Studio 2010:

The default parameter value for 'pageSize' should be a constant compilation time.

+4
source share
1 answer

When you write;

 Rectangle pageSize = PageSize.A4 

Your pageSize value can be changed as a parameter.

From Named and Optional Arguments

The default value must be one of the following expression types:

  • constant expression;

  • expression of the form new ValType (), where ValType is the type of value, such as an enumeration or structure;

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

The PageSize.A4 expression is not classified as a compile-time constant .

+5
source

Source: https://habr.com/ru/post/1468740/


All Articles