How do I use a C# reserved keyword as a property name without the @ prefix? -
i need design class 1 property name has return, when create property name return error.
after research found out 1 can use reserved keyword property or variable name adding @ prefix in c#, or enclosing in square brackets [] in vb.net. example:
var @class = new object(); so here class design code.
public class person { string _retval; public string @return { { return _retval; } set { _retval = value; } } } ... person p = new person(); p.@return = "hello"; now not getting error, when try access property name return need write name @return, don't want. want access property name p.return = "hello"; instead of p.@return = "hello"; i'd know if there way that?
you can't. reserved keyword. means "you can't". contrast "contextual keywords" means "we added later, needed work in pre-existing scenarios".
the moderate answer here is: use @return.
a better answer here is: rename property. perhaps returnvalue.
there option of, say, return - might need think case-insensitive languages too.
Comments
Post a Comment