1

I'm trying to view very basic code looping through models. but, every time I run VS code console app I get this error

The type or namespace name 'List<>' could not be found (are you missing a using directive or an assembly reference?)

The build failed. Fix the build errors and run again.

I use the following command to run the app

dotnet run // to reun console application

what's wrong with the code !!

using System; class Program { static void Main(string[] args) { List<int> list = new List<int>(); } } 
2
  • 1
    I've edited the post to provide minimal reproducible example (instead of wall of code that was there before). Please review that guidance and try to avoid posting unrelated code in your future questions. Commented Sep 14, 2021 at 1:45
  • @AlexeiLevenkov okey I will. thank you Commented Sep 14, 2021 at 7:21

2 Answers 2

3

All you need to know is inside the message ;)

The build failed. Fix the build errors and run again.

-> You are not running your app. It crashes already at the build.

The type or namespace name 'List<>' could not be found (are you missing a using directive or an assembly reference?)

-> You did not Import the type List<>.

-> As you can see in the link below List<> can be imported by "using System.Collections.Generic". This should fix it.

https://learn.microsoft.com/de-de/dotnet/api/system.collections.generic.list-1?view=net-5.0

Sign up to request clarification or add additional context in comments.

Comments

3

the error message is telling you exactly what you need to do, just add with the other using directives:

using System.Collections.Generic; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.