locking - How to lock/unlock a field at runtime in C#? -


can lock/unlock fields or objects @ runtime against writing? in other words changing objects read-only temporarily @ runtime...

for example:

int x = 5; // x 5   lockobject(x);   x = 7; // no change   unlockobject(x);   x = 10; // x 10 

if not can give me possible solutions?

you can use accessors this...

public class x {     private bool locked = false;      private int lockedvar;     public int lockedvar     {         { return lockedvar; }         set { if (!locked) lockedvar = value; }     }      public void lockobject() { locked = true; }     public void unlockobject() { locked = false; } } 

Comments

Popular posts from this blog

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -

openssl - Load PKCS#8 binary key into Ruby -