MOHAMED ABUELATTA
MOHAMED ABUELATTA

Reputation: 345

how to run properly C# code on console app using VS code?

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>();
   }
}

Upvotes: 1

Views: 127

Answers (2)

dennis kaydalov
dennis kaydalov

Reputation: 43

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

using System.Collections.Generic;

Upvotes: 3

sampa
sampa

Reputation: 639

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

Upvotes: 3

Related Questions