Programming in C#: Cannot convert type IEnumerable to List on newest questions tagged c# – Stack Overflow
I have been using C# with Unity3d for a few years now, but am just starting with .NET programming. I get the error:
Cannot implicitly convert type ‘System.Collections.Generic.IEnumerable<URL>‘ to ‘System.Collections.Generic.List<URL>‘. An explicit conversion exists (are you missing a cast?)
Here is my code:
namespace TestBrowserHistory
{
public class Test1
{
public Test1()
{
}
static void Main()
{
InternetExplorer myClass = new InternetExplorer();
List<URL> calledList = myClass.GetHistory();
Console.WriteLine("Hello!");
Console.WriteLine(calledList[1]);
Console.ReadLine();
}
}
}
public class InternetExplorer
{
// List of URL objects
public List<URL> URLs { get; set; }
public IEnumerable<URL> GetHistory()
{
// Initiate main object
UrlHistoryWrapperClass urlhistory = new UrlHistoryWrapperClass();
// Enumerate URLs in History
UrlHistoryWrapperClass.STATURLEnumerator enumerator =
urlhistory.GetEnumerator();
// Iterate through the enumeration
while (enumerator.MoveNext())
{
// Obtain URL and Title
string url = enumerator.Current.URL.Replace('\'', ' ');
// In the title, eliminate single quotes to avoid confusion
string title = string.IsNullOrEmpty(enumerator.Current.Title)
? enumerator.Current.Title.Replace('\'', ' ') : "";
// Create new entry
URL U = new URL(url, title, "Internet Explorer");
// Add entry to list
URLs.Add(U);
}
// Optional
enumerator.Reset();
// Clear URL History
urlhistory.ClearHistory();
return URLs;
}
}
Thanks for any help!
See Answers
source: http://stackoverflow.com/questions/11206957/cannot-convert-type-ienumerable-to-list
Programming in C#: programming-in-c
Recent Comments