简体   繁体   English

如何在Visual Studio中将图像插入图像数组?

[英]How to insert images into image array in visual studio?

The problem is I'm creating an image array inside the class. 问题是我正在类中创建图像数组。 Inside the constructor of the class I'm inserting image elements into the array: 在类的构造函数中,我将图像元素插入数组:

  public sealed partial class MainPage : Page
  {
     Image[] imgs;

     public MainPage()
     {
      imgs={img1, img2, img3, img4, img5, img6, img7, img8, img9, img10, img11, img12, img13, img14}  
     }
  }

These img1, img2, ... are the names of image elements in xaml code. 这些img1,img2,...是xaml代码中图像元素的名称。 Why is it showing errors? 为什么显示错误?

is this all you need...? 这就是您所需要的...吗?

public sealed partial class MainPage : Page
{
   Image[] imgs;
   public MainPage()
   {
      imgs = new Image[] { img1, img2, img3, img4, img5, img6, img7, img8, img9, img10, img11, img12, img13, img14};
   }
 }

Take a look at Object Initializers and probably Arrays 看一下对象初始化器和可能的数组

缺少new声明,也使用分号。

imgs= new[] { img1, img2, img3, img4, img5, img6, img7, img8, img9, img10, img11, img12, img13, img14};

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

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