考虑下面的代码: #include <cstddef>
class A
{
public:
struct B
{
int M;
};
static void StaticFunc();
};
void A::StaticFunc()
{
const std::size_t s0 = sizeof(::A::B::M);
C#7.1引入了一个名为“Default Literals”的新功能,该功能允许使用新的default表达式。 // instead of writing
Foo x = default(Foo);
// we can just write
Foo x = default;
对于Nullable<T>类型,默认值是null,并与通常使用这种按预期工作: int? x = default