Tell IDE that field is set to not null in a method call inside constructor
I'm trying to eliminate some code duplication in my C# project. My class is part of an object pool, so I’d like to set certain fields once in the constructor, and then reinitialize the object later using an Initialize() method.
However, the compiler (and IDE) warns me that my non-nullable fields might not be initialized, since they aren’t all set in the constructor.
Is there a clean way to let the compiler know that these fields will be set later (e.g., in Initialize()), without disabling nullable reference checks or making everything nullable? Example image attached.

2 Replies