+ 1

Why doesn't this code run?

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void result(int x) { int res = x/2; Console.WriteLine(res); } static void Main(string[] args) { result(); } } }

11th Oct 2016, 11:25 PM
roses&mac
roses&mac - avatar
5 Answers
+ 5
that's because you don't pass it any argument, try something like: static void Main (string [] args) { result(4); } you must place a number inside the () or make input field and then pass it as an argument of result
12th Oct 2016, 1:46 AM
Fabricio Bertani
Fabricio Bertani - avatar
+ 1
result(an value)
12th Oct 2016, 7:59 AM
pouria
pouria - avatar
+ 1
thanks
12th Oct 2016, 9:20 AM
roses&mac
roses&mac - avatar
0
It's because "static void result(int x)" method expects an argument to be pass, which is an "int" type, unless you make an optional parameter and set the default value for the argument like "static void result(int x=4)".
12th Nov 2016, 3:27 AM
Jeri Mias
Jeri Mias - avatar
0
as far as i see, your test method has a integer parameter. you must send a number as parameter to result method like this : result(5);
14th Nov 2016, 1:40 PM
Majid Ghafouri
Majid Ghafouri - avatar