Please tell me how you can organize one of the fields of the listing to read / read, and the rest of the fields only to read? For example, there is a class:

public class Item { public enum StateList { OK, Error, Process, Completed } private StateList _State = StateList.OK; public StateList State { get { return _State; } } } 

Here that for Completed and on record.

    3 answers 3

    In general, I created a method in the Item class.

      public void Complete() { _State = StateList.Completed; } 

    I don’t know correctly or not, I’ll have to change the state in such a way without affecting other fields of the listing.

    • one
      This is the most correct solution - Modus

    Since it is impossible to check which value is passed to the setter in compile-time , the only way out is to throw an exception of type ArgumentException at runtime.

      public StateList State { get { return _State; } set { if (value != StateList.Completed) throw new ArgumentException(...); _State = value; } } 
    • every time catching exceptions in performance will probably hit, but thanks for the method anyway, I'll know - Merlin

    Only the method instead of MorphState () is better called Complete ()

    • Made by ) - Merlin