简体   繁体   English

如何使用C#从列表中读取并打印元素?

[英]How to read from a list and print the elements using C#?

I have a list which consists of different bitmap images as elements. 我有一个列表,其中包含不同的位图图像作为元素。 My question is how can I see the content of my list? 我的问题是如何查看清单的内容?

If you just want to see the elements in your list while debugging, either just check the number of elements in the list, or use a Visualizer that actually shows the image. 如果您只想在调试时查看列表中的元素,则只需检查列表中的元素数量,或使用实际显示图像的可视化工具即可

The demand for a Bitmap/Image-Visualizer is quite common: Here's a ready-to-go VS Extension that provides one or write one yourself (it's actually not that hard). 对Bitmap / Image-Visualizer的需求非常普遍: 这是一个现成的VS扩展 ,可以提供一个或自己编写(实际上并不难)。

Example screenshot: 屏幕截图示例:

在此处输入图片说明

You can check Count property then iterate over the images in your list like this: 您可以检查Count属性,然后像这样遍历列表中的图像:

if(list1.Count > 0)
{
    foreach(var img in list1)
    {
        pictureBox3.Image = img;
        await Task.Delay(10); // wait 10 millisecond asynchronously
    }
}

Note: In order to use await , you need to make your method async .See the documentation . 注意:为了使用await ,您需要使您的方法async 。请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM