Hi Ben,
It's possible to use Reflection to get/set the variable value:
public int foo = 1;
public int bar = 2;
private int privateFoo = 1;
public void dosomething(string variablename)
{
Type t = this.GetType();
FieldInfo fi = t.GetField("privateFoo", BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.Public);
Console.WriteLine(fi.GetValue(this));
}
From:
#Early and Late Binding
http://msdn2.microsoft.com/en-us/library/0tcf61s1.aspx
The Visual Basic compiler performs a process called binding when an object
is assigned to an object variable. An object is early bound when it is
assigned to a variable declared to be of a specific object type. Early
bound objects allow the compiler to allocate memory and perform other
optimizations before an application executes.
By contrast, an object is late bound when it is assigned to a variable
declared to be of type Object. Objects of this type can hold references to
any object, but lack many of the advantages of early-bound objects.
C# does not handle late binding.
For late binding related information, please refer to:
#Dynamically Loading and Using Types
http://msdn2.microsoft.com/en-us/library/k3a58006.aspx
Please reply here to let us know whether or not you need further
information. Thank you.
Sincerely,
Walter Wang (
[email protected], remove 'online.')
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.