P
Peter Duniho
[...]
foreach($myObject as $oField => $oValue)
{
printf("%s = %s\n", $oField, $oValue);
/* That gives me an output of MyObject like:
myObjVar = 123
anotherVar = hello world!
*/
}
Is such loop possible in C#, anyhow? (Loop, or rather an object access
mode)
The second question is, directly connected with first one: Is it
possible to access an C# Object such way (PHP sample):
$varName = "myObjVar";
echo $myObject->{$varName};
// That will print out "123"
Anyway to do it in C#?
Both of your questions can be answered in C# using reflection. You'll
want to look at things like the Type class, Type.GetFields() or
Type.GetProperties() (depending on what exactly you're trying to
extract from the type), and the FieldInfo and/or PropertyInfo classes
(again, depending).
Pete