Reputation: 4001
I'm converting some C# code from another project to VB.Net but the following code is throwing an error
Dim obj As System.Collections.ArrayList()
obj = HTMLWorker.ParseToList(New StreamReader("../sample.htm",encoding.Default),
styles)
The error is 'Value of type Systems.Collections.Generic.List() cannot be converted to 'Systems.Collections.Arraylist()'
The original C# code is
System.Collections.ArrayList obj;
obj = HTMLWorker.ParseToList(new StreamReader("../sample.htm",Encoding.Default),
styles);
What would be the correct VB code?
Upvotes: 0
Views: 517
Reputation: 172438
I think this has nothing to do with C#/VB. It appears to me that
The simplest solution is to use type inference:
// C#
var obj = HTMLWorker.ParseToList(new StreamReader("../sample.htm", Encoding.Default), styles);
'' VB
Dim obj = HTMLWorker.ParseToList(New StreamReader("../sample.htm", Encoding.Default), styles)
Note that to use this you need to have "Option Infer" set to "On" in your project properties.
If you don't want to use type inference, you need to declare obj
with the correct type. To determine the correct type, either look up the documentation of ParseToList
or read the information provided by IntelliSense when you type HTMLWorker.ParseToList(
. For example, if ParseToList returns a generic List of IElement
s, the correct syntax is:
Dim obj As Systems.Collections.Generic.List(Of IElement)
obj = ...
Upvotes: 4