© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
10 replies
youssefhabri

❔ 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
Foo
doesn't implement
CreatorId
CreatorId
, and it only works when I have it as
Guid CreatorId
Guid CreatorId


Any idea why this doesn't work? is it even possible to this is C#? 🤔
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Generic nullable type
C#CC# / help
3y ago
❔ giving current class type to a generic class
C#CC# / help
3y ago
How to use Tuple in generic class?
C#CC# / help
4y ago
❔ generic class in generic method
C#CC# / help
3y ago