C#代码已更改为VB [英] C# code being changed to VB
问题描述
如何将C#代码更改为VB.Net
How would I change this C# code to VB.Net
public static List<YouTubeInfo> LoadVideosKey(string keyWord)
{
try
{
var xraw = XElement.Load(string.Format(SEARCH,keyWord));
var xroot = XElement.Parse(xraw.ToString());
var links = (from item in xroot.Element("channel").Descendants("item")
select new YouTubeInfo
{
LinkUrl = item.Element("link").Value,
EmbedUrl = GetEmbedUrlFromLink(item.Element("link").Value),
ThumbNailUrl = GetThumbNailUrlFromLink(item),
}).Take(20);
return links.ToList<YouTubeInfo>();
}
catch (Exception e)
{
Trace.WriteLine(e.Message, "ERROR");
}
return null;
}
我使用了4种不同的代码转换器以及我的代码,但我仍然得到了同样的东西...这是我的代码...
I have used 4 different code converters plus mine and I still get the same thing back... Here is the code from mine...
Public Shared Function LoadVideosKey(keyWord As String) As List(Of YouTubeInfo)
Try
Dim xraw As Object = XElement.Load(String.Format(SEARCH, keyWord))
Dim xroot As Object = XElement.Parse(xraw.ToString())
Dim links As Object = (From item In xroot.Element("channel").Descendants("item")New YouTubeInfo() With { _
Key .LinkUrl = item.Element("link").Value, _
Key .EmbedUrl = GetEmbedUrlFromLink(item.Element("link").Value), _
Key .ThumbNailUrl = GetThumbNailUrlFromLink(item) _
}).Take(20)
Return links.ToList(Of YouTubeInfo)()
Catch e As Exception
Trace.WriteLine(e.Message, "ERROR")
End Try
Return Nothing
End Function
这是Sasha的YouTube查看器中的代码,该代码使用WPF进行了编码.我将其更改为WinForms应用程序,这是我无法使用的唯一代码.
我知道转换后的"Key"一词不是应该存在的,移除后仍然不起作用.我遇到问题的主要代码区域是(将对象链接昏暗= .......")
感谢您的预先帮助...
This is code from Sasha''s YouTube Viewer which was coded in WPF. I am changing this over to a WinForms app and this is the only piece of code that I cant get to work.
I know that the word "Key" is not suppose to be in there after conversion, still does not work after removal. The main area of code that I am having the problem with is the ( "Dim links As Object = ......." )
Thanks for the help in advance...
推荐答案
Dim links As Object = (From item In xroot.Element("channel").Descendants("item")
Select New YouTubeInfo() With { _
.LinkUrl = item.Element("link").Value, _
.EmbedUrl = GetEmbedUrlFromLink(item.Element("link").Value), _
.ThumbNailUrl = GetThumbNailUrlFromLink(item) _
}).Take(20)
如果您不想这样做,可以使用此网站进行转换用手做.
http://www.developerfusion.com/tools/convert/csharp-to-vb/ [ ^ ]
You can just use this webiste for conversions if you are not wanting to do it by hand.
http://www.developerfusion.com/tools/convert/csharp-to-vb/[^]
Public Shared Function LoadVideosKey(keyWord As String) As List(Of YouTubeInfo)
Try
Dim xraw = XElement.Load(String.Format(SEARCH, keyWord))
Dim xroot = XElement.Parse(xraw.ToString())
Dim links = (From item In xroot.Element("channel").Descendants("item")New YouTubeInfo() With { _
Key .LinkUrl = item.Element("link").Value, _
Key .EmbedUrl = GetEmbedUrlFromLink(item.Element("link").Value), _
Key .ThumbNailUrl = GetThumbNailUrlFromLink(item) _
}).Take(20)
Return links.ToList(Of YouTubeInfo)()
Catch e As Exception
Trace.WriteLine(e.Message, "ERROR")
End Try
Return Nothing
End Function
这篇关于C#代码已更改为VB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!