I have question relating to my list and switch statement in my code

Discussion in 'C#' started by wilnicm, Aug 30, 2010.

  1. wilnicm

    wilnicm New Member

    Joined:
    Aug 30, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I want to thank in advance anyone who's able to help me here. Hi my question is relating to my code for my list and Case . The method that i've used RemoveRange only removes the numbers that i have added to my list at certain indexes. Do i need to use a different method or how do i remove it at randomly without removing it at certain indexes. meaning currently if i curently generate a random index and a random number to remove. current if i generate a random index of 2 and random number to remove of 3. it will remove index 3, 4, 5. how do i randomly say. randomly remove at any position. For exampl.. i have numbers 1,2,3,4,5,6. i have a random count of 3 i want to randomly remove 1, 4, 6 instead of removing at certain index. The next question deals with my case statement. currently i have my switch statement related to the count on my list. If the count is equal to 2 i send it to one of my case statement. What i want to do is have the count related to multiple Case statements. Meaning if I return a count of 2 have my application randomly choose one the multiple case statement that i have set for that count. I don't know how to set this case statment properly or if i should be using some other statement such as if or if my doing my switch statemtent all wrong.. ..

    Here is my code for my question..
    Code:
                    List firstlist = new List();
                    Random listRand = new Random();
    
                  //  Predicate mypred = new Predicate();
                   
                    //We add these number from the textbox to a list
                    firstlist.Add(numTxt1);
                    firstlist.Add(numTxt2);
                    firstlist.Add(numTxt3);
                    firstlist.Add(numTxt4);
                    firstlist.Add(numTxt5);
                    firstlist.Add(numTxt6);
    
                    int size = listRand.Next(0,2);
                    int item = listRand.Next(3,5);
                    firstlist.RemoveRange(size,item);
                    //int size = firstlist.Count;
                    //while (size > 0)
                    //{
    
                    //    size--;
                    //    int index = (new Random()).Next(0, size);
                    //    int elem = firstlist[index];
                    //    firstlist[index] = firstlist[size];
    
                    //    MessageBox.Show(elem.ToString());
                    
                    
                    //}
                    //listRand.Next(1, 3);
    
                    //(4 & (1 + mynumb.Next())) - 1
                    int listint01 = 1,
                        listint02 = 2,
                        listint03 = 3;
                    listint01 = firstlist.Count;
                    listint02 = firstlist.Count;
                    listint03 = firstlist.Count;
                    
    
                    switch (firstlist.Count)
                    {
                        case 1: 
                            firstlist[0] = firstlist[0] + 1; 
                            break;
                           
                        //case 1:
                        //    firstlist[0] = firstlist[0] - 1;
                        //    break;
    
                        //case 1:
                        //    firstlist[0] = firstlist[0];
                        //    break;
    
                        case 2:
                            // Add one
                            firstlist[0] = firstlist[0] + 1;
                            firstlist[1] = firstlist[1] - 1;
                            break;
    
                        //case 2:
                        //    // Add one
                        //    firstlist[0] = firstlist[0] - 1;
                        //    firstlist[1] = firstlist[1] + 1;
                        //    break;
    
                        //case 2:
                        //    // Add one
                        //    firstlist[0] = firstlist[0] - 1;
                        //    firstlist[1] = firstlist[1];
                        //    break;
    
                        //case 2:
                        //    // Add one
                        //    firstlist[0] = firstlist[0] + 1;
                        //    firstlist[1] = firstlist[1];
                        //    break;
    
                        case 3:
                            // Add one
                            firstlist[0] = firstlist[0] + 1;
                            firstlist[1] = firstlist[1] - 1;
                            firstlist[2] = firstlist[2];                               
                            break;
    
                        //case 3:
                        //    // Subtract one
                        //    firstlist[0] = firstlist[0] - 1;
                        //    firstlist[1] = firstlist[1] + 1;
                        //    firstlist[2] = firstlist[2];
                        //    break;
    
                        //case 3:
                        //    // Leave as is
                        //    firstlist[0] = firstlist[0];
                        //    firstlist[1] = firstlist[1];
                        //    firstlist[2] = firstlist[2] - 1;
                            
                        //    break;      
                        //case 3:
                        //    firstlist[0] = firstlist[0];
                        //    firstlist[1] = firstlist[1];
                        //    firstlist[2] = firstlist[2] + 1;
                        //    break;
    
                    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice