【问题标题】:Is there a way to declare Guid.Empty as a constant? C# [duplicate]有没有办法将 Guid.Empty 声明为常量? C# [重复]
【发布时间】:2020-05-25 11:50:17
【问题描述】:

出于好奇,有没有办法将 Guid.Empty 声明为 const?我曾经认为所有的值类型都可以声明为常量。

下面的行返回错误:CS0283 The type 'Guid' cannot be declared const

const Guid myConstGuid = Guid.Empty;

【问题讨论】:

标签: c# guid


【解决方案1】:

const 修饰符仅对原始类型有效。

但是,您可以将其声明为 readonly

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 1970-01-01
    • 2014-04-17
    • 2012-05-21
    • 2011-09-17
    • 1970-01-01
    相关资源
    最近更新 更多