+ 1

Problem with "33 Code Project" (Chapter: Methods) / C#-Tutorial

Hey there! :-) I recently tried to solve "33 Code Project" (Chapter: Methods) while working on the C#-tutorial. Here's my solution: ------------------------------------------------------------------------------ using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { int levels = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(Points(levels)); Console.ReadLine(); } static int Points(int anzahlLevel) { int[] myArray = new int[anzahlLevel]; int arrayIndex = 0; while (arrayIndex < anzahlLevel) { myArray[arrayIndex] = ++arrayIndex; } int sumLevel = myArray.Sum(); return sumLevel; } } } ------------------------------------------------------------------------------ I always tried to solve the exercises "my way" and it has never been a problem before. This time I got the following error message: "usercode/file0.cs(27,36): error CS1061: 'int[]' does not contain a definition for 'Sum' and no accessible extension method 'Sum' accepting a first argument of type 'int[]' could be found (are you missing a using directive or an assembly reference?)" My code worked just fine in Visual Studio and the output was correct, too. Could you please tell me what I did wrong? :-/ Thanks in advance! ^-^

13th Oct 2021, 3:08 PM
Sandi
Sandi - avatar
2 Answers
+ 4
you need to import Linq to use Sum() add: using System.Linq;
13th Oct 2021, 3:52 PM
Bahha┣
Bahha┣ - avatar
+ 1
Bahha🐧 Thank you! â˜ș
21st Oct 2021, 6:40 AM
Sandi
Sandi - avatar