简体   繁体   中英

Pass System .Property name as function parameter

I want to create a function which stores some value within

System.Property.Default.my_property.

void foo(property_name, string property_value)
{
System.Property.Default.property_name = property_value;
}

Calls would look like this

foo(my_first_prop, "first");
foo(my_second_prop, "second")

What would be the bast way to do this?

In your code, 'property_name' should be a string, then you can call it like this:

void foo(string property_name, string property_value)
{
    Properties.Settings.Default[property_name] = property_value;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM