r/visualbasic • • Feb 16 '20

This code compiles correctly in VisualStudio but not on hackerrank. On hackerrank it tells me that 'List' is not declared, but the code works in VS. Any suggestions?

Post image
19 Upvotes

9 comments sorted by

3

u/CityEggs VB.Net Beginner Feb 16 '20

Might not be the solution but I've always had to do:

Dim Variable as New list(of string)

1

u/krepzera Feb 16 '20

Hi, thanks for the reply, unfortunately the hackerrank compiler still doesnt seem to have a clue what "List" means which is really odd. Any ideas on how to achieve an equivalent program only using arrays?

4

u/jacderhol VB.Net Advanced Feb 16 '20

Add the following under "Imports System"

Imports System.Collections.Generic

And try again.

2

u/krepzera Feb 16 '20

Full Error:

solution.vb (9,49) : error VBNC30451: 'List' is not declared. It may be inaccessible due to its protection level.  There were 1 errors and 0 warnings.  Compilation took 00:00:00.4777110

3

u/Bonejob VB Guru Feb 16 '20

Hacker Rank name space does not include Generic namespace man. I didn't realize HackerRank supported VB.NET, I have always used it with Python.

1

u/krepzera Feb 24 '20

Very rarely is VB supported on their challenges, so whenever it is I always try and do it in VB as a nice challenge.

5

u/MrWoolve Feb 16 '20

I don't know hackerrank, but Lists and Dictionarys are special features of Microsoft dotnet. They were not included from the beginning. They were introduced later, with Framework 3(?).

Try the predecessors: Collections and Hashtables... https://www.oreilly.com/library/view/vbnet-language-in/0596003080/re51.html ... if these fail too, you have to deal the hard way with Arrays (Redim, Redim preserve).

2

u/TheFotty Feb 16 '20

ArrayList was actually the predecessor to the Generic List(Of) class.

2

u/GYN-k4H-Q3z-75B Feb 16 '20

Visual Studio auto imports System.Collections.Generic and various other namespaces. Always hated that.