Search code examples
c#syntaxchipmunk

Can someone explain this C# static class property?


I'm trying to port someone else's C# code to Xojo. There is the following definition in a class:

static cpCollisionHandler cpCollisionHandlerDefault = new cpCollisionHandler(
         cp.WILDCARD_COLLISION_TYPE, cp.WILDCARD_COLLISION_TYPE,
       DefaultBegin, DefaultPreSolve, DefaultPostSolve, DefaultSeparate, null
    );

I understand that this is static variable that can be returned from the class without instantiating it. I also understand that it is a property called cpCollisionHandlerDefault and that it returns a type of cpCollisionHandler. What I'm not sure about is does this return a new cpCollisionHandler object every time the property is requested from the class or does it return a new object the first time the property is accessed and then the same reference to that cpCollisionHandler for each subsequent request?


Solution

  • does this return a new cpCollisionHandler object every time the property is requested from the class

    No, the program instanciates the field once, the first time the class is loaded

    does it return a new object the first time the property is accessed and then the same reference to that cpCollisionHandler for each subsequent request?

    Yes, it is the same reference for each request