3 times. The following code will help you understand. go to the main function and call the func () function.
class howmanytimescallingafunction { public static int i = 0; public List<string> fun() { List<string> list = new List<string> { "A", "B", "C" }; i++; return list; } public void func() { Console.WriteLine(fun()[0]); Console.WriteLine(i); Console.WriteLine(fun()[1]); Console.WriteLine(i); Console.WriteLine(fun()[2]); Console.WriteLine(i); } }
You must call this function once, get the return value in the local variable List <> and then access it with the variable. eg:
List<string> list = function-that-returns-List<string>(); list[0];
user900360
source share