Optional parameters “must be a compile-time constant”

后端 未结 8 707
面向向阳花
面向向阳花 2020-12-01 15:42

I have a class divided in two partial files, like this:

public partial class PersonRepository : BaseRepository
{
    public static readonly str         


        
相关标签:
8条回答
  • 2020-12-01 16:18

    change

    public static readonly string ColumnID = "ID";
    

    to

    public const string ColumnID = "ID";
    
    0 讨论(0)
  • 2020-12-01 16:23

    Just for completeness, here are the three valid default values for an optional argument: ( from: MSDN: Named and Optional Arguments)

    1. a constant expression
    2. an expression of the form new ValType(), where ValType is a value type, such as an enum or a struct; (note: only the parameterless constructor can be used)
    3. an expression of the form default(ValType), where ValType is a value type.
    0 讨论(0)
提交回复
热议问题