How can I prevent anyone from holding a reference to an object in C#

Posted by floatingfrisbee on Stack Overflow See other posts from Stack Overflow or by floatingfrisbee
Published on 2010-05-05T17:30:17Z Indexed on 2010/05/05 17:38 UTC
Read the original article Hit count: 317

Filed under:

I have a class like this

internal class  Report
{
    public Company TargetCompany { get; private set; }

    .... // other stuff
}

I do not want any one to be able to do this

Report r = GetReport();

Company c = r.TargetCompany;

but instead always use

r.TargetCompany 

when they want access to the Company variable.

Is that possible? Does that even make sense?

© Stack Overflow or respective owner

Related posts about c#