gpt4 book ai didi

c# - "Redundant code detection"在 protected 或更高范围的属性和字段上的工作方式不同

转载 作者:行者123 更新时间:2023-11-30 16:59:04 25 4
gpt4 key购买 nike

在下面的代码示例中,R# 会告诉我赋值是多余的。这对我来说非常有意义。

private string _name = null;   // Redundant code warning

但是,一旦领域/属性(property)得到保护或更高级别,事情就不同了

protected string Name = null; // No Redundant code warning

这是 R# 中的错误还是背后有原因?

最佳答案

这是因为在不查找派生类的情况下,ReSharper 无法判断它是否被使用,因此它过于谨慎并假设它在某处被使用。如果您启用 Solution Wide Analysis,ReSharper 将能够看到整个解决方案,并且知道该字段是否在派生类中使用。然后它会显示冗余代码警告。

关于c# - "Redundant code detection"在 protected 或更高范围的属性和字段上的工作方式不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24331829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com