liloe
It's my birthday today!
- Joined
- Jan 25, 2004
- Messages
- 4,168
Okay, I've started programming again and I chose C# but there is one thing I'd like to know and I don't even know if it's possible without using some workarounds with arrays etc.
Basically I want to have a class MyClass with a x different fields and a SetField(var, value) method to set any of those fields.
Basically I want that people can use SetField(_x, 5) to set _x to 5. Maybe this example is a bit small and sucky, but the question remains: Is that sort of thing even possible?
EDIT: Yes, I know that MyClass._x = 5; would do the trick as well, if I set the fields to public, but I want to know about the other option
Basically I want to have a class MyClass with a x different fields and a SetField(var, value) method to set any of those fields.
Code:
class Myclass
{
private int _x, _y, _z;
public static int SetField(??? field, int value)
{
<--Code here---->
}
}
Basically I want that people can use SetField(_x, 5) to set _x to 5. Maybe this example is a bit small and sucky, but the question remains: Is that sort of thing even possible?
EDIT: Yes, I know that MyClass._x = 5; would do the trick as well, if I set the fields to public, but I want to know about the other option