locked
Method with Arguments used in a Case RRS feed

  • Question

  • Hi, I am trying to use a Method with Arguments within a Case. Look at the code below:

    // A switch case 

    case "t":
     case "T":
     { Test(List<int>temp); } 
     continue;

    // A method

    static void Test(List<int>temp) // How do I refer to this correct?
     { List<int> newTempList = new List<int>(temp);
     Console.WriteLine(newTempList);}

    This throws a error : 

    Error 1 No overload for method 'Test' takes 0 arguments

    Wednesday, June 11, 2014 11:30 PM

Answers

  • You need to do one of the following

    1) Put the list in public area of the program

    2) Make the list public inside a class

    3) Pass the list as a parameter to the method.


    jdweng

    Thursday, June 12, 2014 8:01 AM

All replies

  • Code should look like below

    List<int> temp = new List<int>();
    switch (xxxx)
      case "t":
      case "T":
        Test(temp);
      break;


    jdweng

    Thursday, June 12, 2014 12:13 AM
  • Hi.

    I want to use a List from another Method into a new Method.

    Then I want to refer to the last Method in a Case.

    Thursday, June 12, 2014 7:21 AM
  • You need to do one of the following

    1) Put the list in public area of the program

    2) Make the list public inside a class

    3) Pass the list as a parameter to the method.


    jdweng

    Thursday, June 12, 2014 8:01 AM