0

What's wrong with this code ?

Please can someone tell me why this code displaying errors. https://code.sololearn.com/ce1FiAK20jJH/?ref=app

26th Apr 2020, 10:32 AM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
1 Respuesta
+ 2
1- int numbers = 1-2-3-4-5; this line means that you have ab integer param name numbers with value -13 so you have just one number 2-int newnum = numbers.ToArray(); integer does not have ToArray Methode solution : instead of those two lines use this : int[] newnum =new int[]{1,2,3,4,5}; then in your condition, you should use "==" and correct this line empty += num; so your code is : using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { //int numbers = 1-2-3-4-5; // int newnum = numbers.ToArray(); int[] newnum =new int[]{1,2,3,4,5}; int empty = 0; foreach (var num in newnum) { if (num % 2 == 0) { empty += num; } } Console.Write(empty); } } }
27th Apr 2020, 7:24 AM
Ali pishkari
Ali pishkari - avatar