string str = \"Student_123_\";
I need to replace the last character \"_\" with \",\". I did it like this.
str.Remove(str.Length -1, 1)
No.
In C# strings are immutable and thus you can not change the string "in-place". You must first remove a part of the string and then create a new string. In fact, this is also means your original code is wrong, since str.Remove(str.Length -1, 1);
doesn't change str at all, it returns a new string! This should do:
str = str.Remove(str.Length -1, 1) + ",";