考慮下面的代碼: #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