c# - How to automatically process data when a property is assigned? -


i have many times written c# property looks this:

private string _id; public string id {         {         return _id;     }     set     {         _id = value.trim();     } } 

the above snippet declares string property called id , makes trim extension method automatically called on value passed in setter. without trim logic, have written:

public string id {get; set;} 

it seems i've written lot of code accomplish simple.

is there better way?

is there better way?

well can make look less code (and clutter things less when reading it):

private string _id; public string id {     { return _id; }     set { _id = value.trim(); } } 

or put whole property on single line:

private string _id; public string id { { return _id; } set { _id = value.trim(); } } 

but no, can't make automatically implemented property more trivial get/set private variable.

to honest, it's not code - it's fair amount of syntax you've had declare variable , write 2 statements. don't think that's ask.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -