Remove element from comma separeted string and return new a comma separated string
I am trying to remove a element from a comma separated string. Input : "monkey,bear,cobra"; remove bear Output : "monkey, cobra"; if i do this step by step, it works string[] AnimalArray = AnimalString.Split(','); //split List<string> AnimalList = AnimalArray.ToList();//list AnimalList.Remove("bear");//remove element Console.WriteLine(String.Join(",", AnimalList.ToArray())); //recreate the comma-seperated string if I do this all on one line, I get this error 'bool' does not contain a definition for 'ToArray' string AnimalString2 = "monkey,bear,cobra"; Console.WriteLine(String.Join(",", AnimalString2.Split(',').ToList().Remove("bear").ToArray())); Where is the bool in this action ? What is the best way to do this ? https://code.sololearn.com/c7D1LIM26Tc3