warning 出现于下面的 = slug; 处,请问如何解决?
= slug;
public class BlogPostUrlBuilder(string slug) { private readonly string _slug = slug; }
汗,是一个低级错误引起的,在一个方法中直接访问了构造函数参数 slug,如果不用 primary constructor,是根本没有机会访问的
slug
提问时忘了写 CS9124 的具体警告信息
CS9124: Parameter is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.