0

Why this program won't run on visualstudio ConsoleApp ?

this program is for question 2 in the"Method" " Optional & Named Arguments " and it don't work on visual studio why ? static int calc(int from, int to, int step = 1) { int res = 0; for (int i = from; i < to; i += step) { res += i; } return res; } static void Main(string[] args) { int res = calc(step: 2, to: 99, from: 5); Console.WriteLine(res); }

26th Apr 2018, 10:36 AM
amir ali
amir ali - avatar
3 ответов
0
I'm using VS 2017 and I just ran the code without any problems But I don't think VS version is the problem. Your code on VS any version should look something like this: using System; namespace ConsoleApp1 { class Program { static int Calc(int from, int to, int step = 1) { int res = 0; for (int i = from; i < to; i += step) { res += i; } return res; } static void Main(string[] args) { int res = Calc(step: 2, to: 99, from: 5); Console.WriteLine(res); } } }
26th Apr 2018, 11:05 AM
ODLNT
ODLNT - avatar
0
thanks a lot yes your true , i'm forget some code
26th Apr 2018, 1:31 PM
amir ali
amir ali - avatar
0
You are welcome Good luck with your coding!
26th Apr 2018, 1:41 PM
ODLNT
ODLNT - avatar