Maybe You are in need of indexer ?
As I cannot assume anything about k
but it consists of fields id
and fields
(both unknown type) and as You are trying to use a string
variable as a key You would either need the fields
to be of type IDictionary<string, ...>
or You can provide an indexer for the class of fields
.
1) Dictionary:
k.fields = new Dictionary<string, string>();
...
string CustomField = ...;
epicKey = k.fields[CustomField]
2) Indexer
Let assume that fields
inside k
is a type of SomeClass
. Then inside SomeClass
:
public class SomeClass
{
...
public string this[string key] {
get {
return ...
}
set {
...
}
}
}
assuming that You are storing all those values somewhere else and indexer is only a way to get them from it, to make this syntax proper:
string CustomField = ...;
epicKey = k.fields[CustomField]
To summarise:
fields
is already well defined class and You just need to add a support of indexing or handle some custom logic of setting or getting values: use indexer,
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.