You need to make it a generic method: public static void Shuffle(this List source) { Random rnd = new Random(); for (int I = 0; I Count); T o = source0; source. RemoveAt(0); source. Insert(index, o); } } That will allow it to work with any List.
3 I've got to learn to type faster. Anyway, IList would be more general. – John Saunders Aug 15 '09 at 1:22 when I try all the methods listed I get... Argument '2': cannot convert from 'object' to 'T' – Grant Aug 15 '09 at 1:25 1 @Grant: You need to change the portion in the middle to use "T" instead of "object" (or add a cast).
As John mentioned, using IList would be more general, although not all IList implement insertion, so it may not work generally. – Reed Copsey Aug 15 '09 at 1:29 IList has the Insert method. What class implements IList and does not implement Insert?
– John Saunders Aug 15 '09 at 1:34 @John: Any implementation with ICollection. IsReadOnly set to true often throws on insert. I've had this bite me before.
See: msdn.microsoft. Com/en-us/library/0cfatk9t. Aspx – Reed Copsey Aug 15 '09 at 1:48.
You just make your own method generic: public static void Shuffle(this List source).
Slightly off-topic, but a Fisher-Yates shuffle will have less bias and better performance than your method: public static void FisherYatesShuffle(this IList source) { Random rng = new Random(); for (int n = 0; n Count); T tmp = sourcek; sourcek = sourcen; sourcen = tmp; } }.
I Think this solution faster to process, because you will get your itens randomly and your collection position will be preserved to future use. Namespace MyNamespace { public static class MyExtensions { public static T GetRandom(this List source) { Random rnd = new Random(); int index = rnd. Next(0, source.
Count); T o = sourceindex; return o; } } } Steps: Create your Static Class to Identify your extensions Create you Extension Method (must be static) Process your data.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.