Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过linq获得乘法结果_C#_Linq_Youtube - Fatal编程技术网

C# 通过linq获得乘法结果

C# 通过linq获得乘法结果,c#,linq,youtube,C#,Linq,Youtube,我对linq有一个问题,我想从youtube xml中得到多个结果,但这段代码只给出一个结果,有人知道如何解决这个问题吗 key = @"http://gdata.youtube.com/feeds/api/videos?q="+keys+@"&orderby=relevance"; var youtube = XDocument.Load(key); var urls = (from item in youtube.Elements("{http://www.w3.org/2005/A

我对linq有一个问题,我想从youtube xml中得到多个结果,但这段代码只给出一个结果,有人知道如何解决这个问题吗

key = @"http://gdata.youtube.com/feeds/api/videos?q="+keys+@"&orderby=relevance";
var youtube = XDocument.Load(key);
var urls = (from item in youtube.Elements("{http://www.w3.org/2005/Atom}feed")
                select new
                {
                    soundName = item.Element("{http://www.w3.org/2005/Atom}entry").Element("{http://www.w3.org/2005/Atom}title").ToString(),
                    url = item.Element("{http://www.w3.org/2005/Atom}entry").Element("{http://www.w3.org/2005/Atom}id").ToString(),
                });
youtube xml:
谢谢你的帮助

您需要获取每个
条目
元素(很可能有一种更简洁的编写方法:

    var urls = (from item in youtube.Element("{http://www.w3.org/2005/Atom}feed").Descendants("{http://www.w3.org/2005/Atom}entry")
                select new
                {
                    soundName = item.Element("{http://www.w3.org/2005/Atom}title").ToString(),
                    url = item.Element("{http://www.w3.org/2005/Atom}id").ToString(),
                });
var test = (from item in youtube.Elements("{http://www.w3.org/2005/Atom}feed")
            from entries in item.Elements("{http://www.w3.org/2005/Atom}entry")
                select new
                {
                    soundName = entries.Element("{http://www.w3.org/2005/Atom}title").ToString(),
                    url = entries.Element("{http://www.w3.org/2005/Atom}id").ToString(),
                });
应该给你所有你想要的条目

编辑:Max的答案更简洁=D

        XNamespace ytNs = "http://www.w3.org/2005/Atom";
        var youtube = XDocument.Load(key);
        var urls = (from item in youtube.Elements(ytNs + "feed").Elements(ytNs + "entry")
                    select new
                        {
                            soundName = item.Element(ytNs + "title").ToString(),
                            url = item.Element(ytNs + "id").ToString(),
                        });