youssefhabri
youssefhabri
CC#
Created by youssefhabri on 12/30/2022 in #help
❔ How to make a generic class property nullable?
I'm trying to have a generic interface with a nullable property:
public interface IMayHaveCreator<TKey>
{
TKey? CreatorId { get; set; }
}
public interface IMayHaveCreator<TKey>
{
TKey? CreatorId { get; set; }
}
But this doesn't work, as when I add it to a class, it gives an error when I try to make the implementation nullable aswell:
public class Foo : IMayHaveCreator<Guid>
{
public Guid? CreatorId { get; set; }
}
public class Foo : IMayHaveCreator<Guid>
{
public Guid? CreatorId { get; set; }
}
I says that Foo doesn't implement CreatorId, and it only works when I have it as Guid CreatorId Any idea why this doesn't work? is it even possible to this is C#? 🤔
11 replies