我使用C#和Unity3d已经有几年了,但是现在刚开始学习.NET编程。我遇到了以下错误:
无法隐式转换类型 'System.Collections.Generic.IEnumerable<URL>
' 到 'System.Collections.Generic.List<URL>
'。 显式转换存在(是否缺少强制转换?)
这是我的代码:
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;
}
}
感谢任何帮助!