c# - Not all code return a value for lists -


i dont know error is, im trying retrieve values list , add them, dont know happening in code, error occurs @ returnattacks , attackloop.

public class test{     public static list<int> attacks = new list<int>();     public static void addattack(int attack){         attacks.add (attack);      }      public static int returnattacks(){         int numofattacks = attacks.count;         int returnval = 10;         if (numofattacks > 5) {             return returnval;         }         attackloop();     }     public static int attackloop(){         foreach (int attack in attacks) {             return attack;         }     }      public static void main()     {         addattack(1);         addattack(2);         addattack(3);         addattack(4);         addattack(5);         addattack(6);         int selection = returnattacks();      }  } 

in attackloops () function, function returns value of attack in first iteration of loop, , it. try returning value outside loop, or go generator function. hope helps.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -