C
C#3mo ago
abdesamed

Why I'm getting this error

No description
No description
13 Replies
!τ$TAo_mickey[τ, τ]
try like this
No description
abdesamed
abdesamed3mo ago
it won't work since there is a required parameter
abdesamed
abdesamed3mo ago
No description
!τ$TAo_mickey[τ, τ]
u can update the constructor?
abdesamed
abdesamed3mo ago
update it how?
abdesamed
abdesamed3mo ago
I don't want the possibility of an empty string
!τ$TAo_mickey[τ, τ]
then update like this
abdesamed
abdesamed3mo ago
I think there is a better way
!τ$TAo_mickey[τ, τ]
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
abdesamed3mo ago
I removed the contractor, the object initializer works now thanks for the help
!τ$TAo_mickey[τ, τ]
you are welcome
Want results from more Discord servers?
Add your server