locked
system.web.ui.webcontrols.image in c# class is it possible? RRS feed

  • Question

  • I' d like to create an object like this:

    public class classname

    {

      public int property1 {get;set;}

      public list<system.web.ui.webcontrols.image> images {get;set;}

    }

    classname cn = new classname();

    image img = new image();

    image.imageurl = "somepath";

    cn.images.add(img);   // error here

    I wrote a code like that and I got an error instance not set to instance of an object

    Saturday, December 1, 2012 7:33 PM

Answers

  • Hi,

    This is because that the images is null, you can create a instance in the constructor:

    public class classname

    {

      public int property1 {get;set;}

      public List<system.web.ui.webcontrols.image> images {get;set;}

      public classname()  {

        images=new List<system.web.ui.webcontrols.image>();

       }

    }

    Using Constructors (C# Programming Guide)

    http://msdn.microsoft.com/en-us/library/ms173115.aspx


    Leo Tang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by LeoTang Sunday, December 9, 2012 1:20 PM
    Monday, December 3, 2012 10:02 AM