+ 1

How does one assign the value obtained of concatenation of two string variables to an object type identifiers' initialization?

Declare two identifiers of type string and initialize them then declare an identifier of of type object.

17th Apr 2017, 10:27 PM
Mandla Phillip Ndimande
Mandla Phillip Ndimande  - avatar
1 Réponse
0
Not sure what you want to accomplish. Identifiers do not get initialized, they are given by (usually) compiled code and cannot be changed dinamically. You want to make an object with the identifier gained from adding two strings? The nearest solution could be like that: string s1 = "a", s2 = "b"; SomeObject o = new SomeObject(); o.SetField(a + b, o); class SomeObject { Dictionary<string, object> fields = new Dictionary<string, object>(); public object GetField(string id) { if (fields.Keys.Contains(id)) return fields[id]; return null; } public void SetField(string id, object val) { if (val == null) { if (fields.Key.Contains(id)) fields.Remove(id); return; } if (fields.Keys.Contains(id) fields[id] = val; else fields.Add(id, val); } }
18th Apr 2017, 12:03 PM
Magyar Dávid
Magyar Dávid - avatar