I am trying to create an extension method for a string that takes one argument and adds the argument to the string value. Here is the behavior I want:
public static void AddNumber(this string originalValue, string id) { List<string> ids = originalValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToString(); ids.Add(id); string newValue = string.Join(",", ids); originalValue = newValue; }
Then I would use it as follows:
string testing = ""; testing.AddNumber("1");
The problem is that I see this:
string testing = ""; testing.AddNumber("1"); // value is "" testing.AddNumber("2"); // value is "" testing.AddNumber("3"); // value is ""
Now I read this one ! here on StackOverflow, and I know that I am doing this. I canβt replace the whole value of the string, I need to change the contents of the string that is sent through ... I just canβt find a way to change it. I tried modifying an array of characters and no luck. Any ideas?
source share