C
C#7mo ago
abdesamed

Why I'm getting this error

No description
No description
13 Replies
GenTAO[τ, τ]
GenTAO[τ, τ]7mo ago
try like this
No description
abdesamed
abdesamedOP7mo ago
it won't work since there is a required parameter
abdesamed
abdesamedOP7mo ago
No description
GenTAO[τ, τ]
GenTAO[τ, τ]7mo ago
u can update the constructor?
abdesamed
abdesamedOP7mo ago
update it how?
GenTAO[τ, τ]
GenTAO[τ, τ]7mo ago
No description
abdesamed
abdesamedOP7mo ago
I don't want the possibility of an empty string
GenTAO[τ, τ]
GenTAO[τ, τ]7mo ago
No description
GenTAO[τ, τ]
GenTAO[τ, τ]7mo ago
then update like this
abdesamed
abdesamedOP7mo ago
I think there is a better way
GenTAO[τ, τ]
GenTAO[τ, τ]7mo ago
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; } }
abdesamed
abdesamedOP7mo ago
I removed the contractor, the object initializer works now thanks for the help
GenTAO[τ, τ]
GenTAO[τ, τ]7mo ago
you are welcome

Did you find this page helpful?