c# - This Lambda OrderBy seems superfluous in my case - is it? -


i don't want have unnecessary code, want "safe," too. empirical observations have shown orderby below nothing - list ordered correctly. can rely on being case, , remove orderby line?

hashset<int> hashset = new hashset<int>(); list<int> listints = new list<int>(); using (var file = new system.io.streamreader(selectedfile)) {     string line;     int linenum = 0;     int offset = (int)numericupdownlinesofcontext.value;     while ((line = file.readline()) != null)     {         linenum++;         if (line.contains(platypustosearchfor)) {             // adds lines before , after provide desired context             // (n lines log file before , after searched value)             hashset.unionwith(enumerable.range(linenum - offset, offset * 2 + 1));         }     }     // remove negative numbers, 0, might have been added      // (0, -1, -2, or -3 possibilities, first line #1)     listints = hashset.where(i => >= 1).tolist();     // seem ordered correctly already, in case:     listints = listints.orderby(i => i).tolist(); } 

no, shouldn't remove orderby. hashset not guarantee particular ordering. may lucky in testing, can't guarantee order things way expect to.

from msdn documentation on hashset (http://msdn.microsoft.com/en-us/library/bb359438.aspx):

a set collection contains no duplicate elements, , whose elements in no particular order.

(emphasis added)


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -