The Substring method returns a new fresh copy of the string copied from the original one. If you want to "cut the extension", then you should get what the substring returns and store somewhere, that is:
int i = list1[n].LastIndexOf("."); if (i > 0) list1[n] = list1[n].Substring(0, i);
However, this is a rather strange way to remove an extension.
Firstly, using Substring(0,idx) is odd, since there is Remove(idx) (link) , which does just that:
int i = list1[n].LastIndexOf("."); if (i > 0) list1[n] = list1[n].Remove(i);
But, sencondly, there is an even better way to do this: the System.IO.Path class provides you with a set of well-written static methods that, for example, remove the extension (editing: this is what L-Three suggests in the comments), with full point processing etc.:
var str = System.IO.Path.GetFileNameWithoutExtension("myfile.txt");
See MSDN link
It still returns a copy, and you still need to save the result somewhere!
list1[n] = Path.GetFileNameWithoutExtension( list1[n] );
source share