VS csproj设置

手动关联xaml与cs文件

复用其他控件,添加现有项时无法关联

    <Compile Include="ControlsUC_Loading.xaml.cs">
      <DependentUpon>UC_Loading.xaml</DependentUpon>
    </Compile>

启用可空引用

启用 C# 8.0 的语法支持
在项目文件中开启可空引用类型的支持

定义 说明 备注
string aa 不可为空 aa就是不可为空的引用类型
string? aa 可为空 aa就是可为空的引用类型
method(string aa) 未知 对于类型参数来说,可能不能确定是否是可空引用类型
static void Main(string[] args)
{
    Test(null);;
}

#nullable enable
readonly static string? _name = null;
private static void Test(string name)
{
    int len = name.Length;
    int len2 = _name.Length + len;
}
#nullable disable

len2 计算时会提示 _name可能为null

显示引用次数

原文地址:https://www.cnblogs.com/wesson2019-blog/p/14186394.html