3

i am having some file names in array list Like, "Form.frm,Form1.frm,Form2.frm,Module.bas,Module23.bas" in the array list i want to make the first item as ".bas" files how can i make it using array list.

4
  • Could you be more specific about what you want the output to be? Also, is there any reason you're using an ArrayList instead of a List<string> -- ArrayList is obsolete. Commented Oct 30, 2012 at 13:05
  • Try having a look at this: stackoverflow.com/questions/188141/… Hope it helps. Also try to use List<T> instead of Arrays, they are easier to handle Commented Oct 30, 2012 at 13:06
  • this is an existing code. already they are using arrylist only. if i change arraylist to List<string> means it will affect so many place. Commented Oct 30, 2012 at 13:09
  • i am working on migrating tool vb to C# ".bas" files are like class file in vb. so that i want read class file first to fetch all the variables and function. Commented Oct 30, 2012 at 13:13

2 Answers 2

5

First i would suggest to use the strongly typed List<T> instead. You can use Path.GetExtension and Linq's Enumerable.OrderBy:

List<String> files = new List<String>(){ "Form2.frm","Module.bas","Module23.bas" };
var ordered = files.OrderBy(fn => Path.GetExtension(fn));
Sign up to request clarification or add additional context in comments.

Comments

2

I understand that you want to order the items by the extension, this can be done in this way:

        List<string> fileNames = new List<string>();
        fileNames.Add("Form.frm");
        fileNames.Add("Form1.frm");
        fileNames.Add("Form2.frm");
        fileNames.Add("Module.bas");
        fileNames.Add("Module23.bas");

        var ordered = fileNames.OrderBy(p => Path.GetExtension(p));

1 Comment

Damn 5 minutes of slow connection :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.