使用 C# 9,您可以执行以下操作:
public record Person(string FirstName, string LastName);
定义记录 Person
.这相当于:public record Person
{
public string FirstName { get; init; }
public string LastName { get; init; }
public Person(string firstName, string lastName)
=> (FirstName, LastName) = (firstName, lastName);
public void Deconstruct(out string firstName, out string lastName)
=> (firstName, lastName) = (FirstName, LastName);
}
根据 this page .因此,元素
FirstName
和 LastName
作为构造函数的属性和参数。作为属性,这些元素应该大写,但如果我这样做,SA1313 会提示:Parameter '__' must begin with lower-case letter.
.这是 StyleCop 的问题还是我做错了什么?
最佳答案
这是 StyleCop 和 it's been fixed for the 1.2.0-beta.261 release 中的一个问题.
关于位置记录 : should be disabled? 中的 StyleCopAnalyzers/SA1313,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64884856/