gpt4 book ai didi

c# - 虚拟成员的语法

转载 作者:太空狗 更新时间:2023-10-29 18:11:20 25 4
gpt4 key购买 nike

考虑以下用 c# .net 4.0 编写的类(通常在 nhibernate 类中找到):

public class CandidateEntity : EntityBase
{
public virtual IList<GradeEntity> Grades { get; set; }

public CandidateEntity()
{
Grades = new List<GradeEntity>();
}
}

这一行得到了一个有根据的警告“构造函数中的虚拟成员调用”。我应该在哪里初始化这个集合?

问候,

最佳答案

支持字段是一种方式。另一种是使用私有(private)二传手。这在 nHibernate 中运行良好。

public virtual IList<GradeEntity> Grades { get; private set; }

public CandidateEntity()
{
Grades = new List<GradeEntity>();
}

关于c# - 虚拟成员的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4776049/

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