0
public static string[] traitNames = { "Happiness", "Respect", "Authority" };
public static string[] suppliesNames = { "Food", "Iron", "Gold" };
private List<string[]> arraysNames = new List<string[]> { traitNames, suppliesNames };
string[] currentArrayNames = arraysNames[i1];
int namesCount = currentArrayNames.Count;//ERROR HERE

Hello! For some reason, on the last line where I try to Count, I get an error message over Count:

Cannot convert method group "Count" to non-delegate type 'int'.

How would I be able to Count currentArrayNames' amount of children without getting this counting error? Thanks.

5
  • stackoverflow.com/questions/59100928/… Commented Nov 29, 2019 at 9:36
  • Does this answer your question? Setting a List to another List in C# Commented Nov 29, 2019 at 9:40
  • Remove using System.Linq and the error will suddenly make more sense Commented Nov 29, 2019 at 9:55
  • 2
    Or use Count() - note () - from Linq which is the same for all collections Commented Nov 29, 2019 at 9:57
  • Please, have a look at updated answer Commented Nov 29, 2019 at 11:33

1 Answer 1

2

Use currentArrayNames.Length, there is no Count property in Array class

int namesCount = currentArrayNames.Length;

Another option is to use Count() extension method from System.Linq namespace, as you've tried to done, but this is a method, not a property

int namesCount = currentArrayNames.Count();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.