13 Replies
try like this
it won't work since there is a required parameter
u can update the constructor?
update it how?
I don't want the possibility of an empty string
then update like this
I think there is a better way
public class Peer
{
public Peer(string name, Guid guid)
{
Name = string.IsNullOrWhiteSpace(name)
? throw new ArgumentException("Name cannot be empty or whitespace.", nameof(name))
: name;
Guid = guid; Friends = new List<Peer>(); } [Key] public Guid Guid { get; set; } public required string Name { get; set; } public List<Peer>? Friends { get; set; } }
Guid = guid; Friends = new List<Peer>(); } [Key] public Guid Guid { get; set; } public required string Name { get; set; } public List<Peer>? Friends { get; set; } }
I removed the contractor, the object initializer works now
thanks for the help
you are welcome