C# properties

Hi there,

I wanted to know - how does compiler/CLR will decide as whether to call “set” or “get” accessor of property defined under a class for a field of class.

Will compiler add any logic to determine the type of call (set or get) when an instruction like "something = something"occurs?

Thanks for your help in advance.

The C# property accessors are implented by generating functions with “get_” and “set_” prefixes. E.g. if you have a property named “UserName”, the underlying CLR will generate a call to functions “get_UserName” or “set_UserName” as necessary.

So the statement “UserName = “gsneelager”;” actually generates CLR like “set_UserName(“gsneelager”);”

1 Like