C#: custom array sorting -


I would like to sort an array of strings (considering the custom mapping (this is actually the basis of the stock names) On field) I have uncertainty about what data structures to use to represent mapping, and how to write a custom sort method.

For example, suppose I had the following string array:

  string [] fileNames = "bac.csv", "c.csv", "cvx. Csv "," Java.csv "," msft.csv "," xom.csv ";  

And here are the mappings:

  {"bac", "c"} = & gt; 0 {"MSFT", "Java"} = & gt; 1 {"xom", "cvx"} = & gt; 2  

I want to return the string [] customsrt (string [] filename to return the following [/ p>

  "bac.csv", "c.csv) "," Java.csv "," msft.csv "," xom.csv "," cvx.csv " 

what data structure will you use to represent mapping, What's the best way to write sort method?

array The location allows you to specify an array of keys, so that you can do something like this ...

  int [] key = new int [fileNames.Length]; Dictionary & lt; String, int & gt; Mapping = New Dictionary & lt; String, int & gt; (String compiler, contentcultural industry cass); // Set up our mapping like mapping. Add ("BAC", 0); Mapping Add ("C", 0); Mapping Add ("MSFT", 1); Mapping Add ("Java", 1); Mapping Add ("xom", 2); Mapping Add ("cvx", 2); // etc (int i = 0; i & lt; keys.Length; i ++) {string token = System.IO.Path. GetFileNameWithoutExtension (filename [i]); Of int mapping; If (! Mapping.Terriget value (token, mapping mac)) of mapping = int.MaxValue; Key [ii] = mapping; } Array.keeping & lt; Int, string & gt; (Keys, filename); To get the proper value from your mapping given to   

token variable, simply keys [i] = 1; Modify the statement.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -