Convert List<object> to List<int>

How to easily convert a list of objects to a list of primative types

If you have a generic List<object> of class objects, and want to generate a list of primative type based on a single class property, use the following...

C#
var newList = myList.ConvertAll(x => x.myProp);
VB.Net
Dim newList As List(of Integer) = myList.ConvertAll(Function(x) x.myProp)

It is not necessary to cast the primative type.

Added 22/02/2023 12:10

URI encoding in Javascript

Difference between encodeURI and encodeURIComponent

I can never remember the difference between encodeURI and encodeURIComponent when encoding data for inclusion on URI/URLs.

For general use, encodeURIComponent is what I need, as it also encodes the following characters: ; / ? : @ & = + $ , #

Added 10/02/2023 10:18

Merging jQuery objects

How to merge jQuery objects for method chaining

When working with jQuery, you sometimes have two or more objects for specific functionality...

$one = $("#one");
$two = $("#two");
$three = $("#three");

But what if you want to call methods on all of them at the same time?  Instead of..

$one.show().addClass("myClass");
$two.show().addClass("myClass");
$three.show().addClass("myClass");

You can .add() them together...

$one.add($two).add($three).show().addClass("myClass");

This has the advantage of being non-destructive, so it does not effect the first object (unlike $.merge)

Added 09/02/2023 15:54