( ! ) Warning: Parameter 1 to wp_default_styles() expected to be a reference, value given in /home/www/dotmos/wp-includes/plugin.php on line 546
Call Stack
#TimeMemoryFunctionLocation
10.0004351304{main}( ).../index.php:0
20.0007351656require( '/home/www/dotmos/wp-blog-header.php' ).../index.php:17
30.15842398720require_once( '/home/www/dotmos/wp-includes/template-loader.php' ).../wp-blog-header.php:16
40.15842398720do_action( ).../template-loader.php:12
50.15852399144CrayonWP::wp_head( ).../plugin.php:470
60.15852399144CrayonWP::enqueue_resources( ).../crayon_wp.class.php:884
70.15862399256wp_enqueue_style( ).../crayon_wp.class.php:548
80.15872399600WP_Styles->__construct( ).../functions.wp-styles.php:164
90.15872400000do_action_ref_array( ).../class.wp-styles.php:39

( ! ) Warning: Parameter 1 to wp_default_scripts() expected to be a reference, value given in /home/www/dotmos/wp-includes/plugin.php on line 546
Call Stack
#TimeMemoryFunctionLocation
10.0004351304{main}( ).../index.php:0
20.0007351656require( '/home/www/dotmos/wp-blog-header.php' ).../index.php:17
30.15842398720require_once( '/home/www/dotmos/wp-includes/template-loader.php' ).../wp-blog-header.php:16
40.15842398720do_action( ).../template-loader.php:12
50.15852399144CrayonWP::wp_head( ).../plugin.php:470
60.15852399144CrayonWP::enqueue_resources( ).../crayon_wp.class.php:884
70.15972412856wp_enqueue_script( ).../crayon_wp.class.php:549
80.15972413264WP_Scripts->__construct( ).../functions.wp-scripts.php:201
90.15972413264WP_Scripts->init( ).../class.wp-scripts.php:34
100.15972413664do_action_ref_array( ).../class.wp-scripts.php:46
DOTMOS » How to sort Lists in C# or: IComparer rocks!

How to sort Lists in C# or: IComparer rocks!

Posted by on Feb 26, 2014 in Game Development, Programming | No Comments

For a game i’m working on i needed to sort cities based on the commodities that are sold in these cities. The list should be sortable by buy/sell price, estimated profit with current player cargo and city names.

As my commodity and city classes are quite complex i feared that i would have to write a custom search class for this. As i didn’t really wanted that, i had a look around and soon found out, that C# has numerous ways of helping the user sorting his stuff. In fact, lists already have a Sort() function implemented which uses Quick Sort.

My first implementation looked something like this:

This worked great, but i wanted a more general approach which would not only let me  sort cities based on commodity prices, but virtually anything. So i had a look at IComparer which is actually exactly what i needed.
Basically you just write a custom comparer for each class you want to sort, pass that to the list’s Sort() function and you are set. Great!

And here’s how to use it:

Now i can sort my cities based on their commodities, name, size, position, citizens and how many pieces of socks each citizen owns. I just have to pass a coresponding comparer to my GetSortedCities() function!

More sorting goodness can be found in this awesome stackoverflow thread.