Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.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# MS图形循环浏览IListite MSCollection页面中的每个项目_C#_.net_Microsoft Graph Api - Fatal编程技术网

C# MS图形循环浏览IListite MSCollection页面中的每个项目

C# MS图形循环浏览IListite MSCollection页面中的每个项目,c#,.net,microsoft-graph-api,C#,.net,Microsoft Graph Api,我有一段代码,从SPO列表中提取项目。我应该如何编写foreach/select类型才能读取item.Title f.e 尝试将var项键入多个类型,但无法获得正确的结果 var items = await graphServiceClient.Sites["yourtenant.sharepoint.com:/sites/ITOddeleni:"].Lists["TeamsRequest"].Items .Request(queryOptions) .GetAsync();

我有一段代码,从SPO列表中提取项目。我应该如何编写foreach/select类型才能读取item.Title f.e

尝试将var项键入多个类型,但无法获得正确的结果

var items = await graphServiceClient.Sites["yourtenant.sharepoint.com:/sites/ITOddeleni:"].Lists["TeamsRequest"].Items
     .Request(queryOptions)
     .GetAsync();

foreach (var item in items)
{
    Console.WriteLine(item);
}
我希望它写出一个带有项目标题的字符串。 现在我只得到了2倍的Microsoft.Graph.ListItem,因为我在列表中有2项

var queryOptions = new List<QueryOption>()
                {
                    new QueryOption("expand", "fields(select=id,Title)")
                };



                var items = await graphServiceClient.Sites["yourtenant.sharepoint.com"].Lists["TeamsRequest"].Items
                     .Request(queryOptions)
                     .GetAsync();




                foreach (var item in items)
                {
                    Console.WriteLine(item.Fields.AdditionalData["Title"]);
                    Console.WriteLine("Name:" + item.Name);
                    Console.WriteLine($"ID: {item.Id}");
                }

item.Fields.AdditionalData执行此操作。感谢您的建议:-

您阅读的是ToString方法的输出,该方法由C中的每个对象从类对象继承。如果未被覆盖,它将在默认情况下按您的情况打印整个类名。您需要手动打印它,所有您希望读取的值使其成为Console.WriteLineitem.ToString;没有改变一件事,我弄错了吗?是的,您需要编写Console.WriteLine$Title:{item.Title}或类似的东西。我不知道item是什么数据类型…Microsoft.Graph.ListItem它是。。。设法通过Console.WriteLine$Title:{item.ID}获取它的ID,但它根本不建议使用Title:-名称如何?看一看地图