Hello,

I am trying to declare a 2D List Globally. I beleive I miss something out in my declaration.

It seems that I can declare the list. But when I try to add 1 dimension to the list, it only
accepts: "new Requests.GlobalVariables.list2()"
when it should be: new Requests.GlobalVariables.list1()

I wonder what I can be doing wrong?

      //Global declaration
        public class list1 : List<int> { };
        public class list2 : List<list1> { };
        private static List<list2> _list;
        public static List<list2> list
        {
            get { return _list; }
            set { _list = value; }
        }


        Requests.GlobalVariables.list = new List<Requests.GlobalVariables.list2>(); //Declare
        Requests.GlobalVariables.list.Add(new Requests.GlobalVariables.list1()); //Add 1 dimension element

Recommended Answers

All 2 Replies

If you look at your declaration of _list, it is a List of type list2 objects. This means that all objects added to the list must be of type list2 or inherit from type list2. The list1 type inherits from the List<int> type, so it can't be added to the list since it is not a list2 type and it does not inherit from a list2 type.

Thanks for help, it solved it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.