Random r = new Random(); int InvadorNumberA=r.Next(0,5); int randomShot = r.Next(5); List<Invaders> invadersShooting = new List<Invaders>(); Invaders invaderA=new Invaders(); var invaderByLocationX = from invadersSortByLocation in invaders group invadersSortByLocation by invadersSortByLocation.Location.Y into invaderGroup orderby invaderGroup.Key select invaderGroup; invadersShooting = invaderByLocationX.Last().ToList(); try { invaderA = invadersShooting[InvadorNumberA];
stack trace
"in System.ThrowHelper.ThrowArgumentOutOfRangeException (argument ExceptionArgument, resource ExceptionResource) \ r \ n in System.ThrowHelper.ThrowArgumentOutOfRangeException () \ r \ n in System.Collections.Generic.List`1.get_Item (index n32) in WindowsFormsApplication1.Game.ReturnFire () in D: \ Documents and Settings \ Dima \ My Documents \ Visual Studio 2008 \ Projects \ SpaceInvaders \ SpaceInvaders \ SpaceInvadorGame \ Game.cs: line 444 "
Destination site
{Void ThrowArgumentOutOfRangeException (System.ExceptionArgument, System.ExceptionResource)}
Additional Information:
{"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}
{"The index was out of range. Must be non-negative and smaller than the size of the collection. \ R \ nParameter: index"}
I got rid of the exception by just doing it
invadersShooting = invaderByLocationX.Last().ToList(); invaderA = invadersShooting[r.Next(0,invadersShooting.Count)];
but I'm still wondering where the exception was thrown..hmmm
source share