1

问题是我正在类中创建一个图像数组。在类的构造函数中,我将图像元素插入到数组中:

  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}  
     }
  }

这些 img1, img2, ... 是 xaml 代码中图像元素的名称。为什么会显示错误?

4

2 回答 2

5

这就是你所需要的……?

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};
   }
 }

看看对象初始化器和可能的数组

于 2013-08-06T14:22:36.893 回答
2

缺少一个new语句,还有一个分号。

imgs= new[] { img1, img2, img3, img4, img5, img6, img7, img8, img9, img10, img11, img12, img13, img14};
于 2013-08-06T14:22:12.607 回答