locked
What is the max limit for a 2 dimensional Arraylist can I increase or decrease it whenever needed RRS feed

  • Question

  • User1182587605 posted

    Hi,

    I want to know if there was a maximum limit for values in a 2-dimensional array. Can I declare arr[550000][7] or should I have another way of doing this? Please suggest to me the best  way to increase/decrease an ArrayList hugely and make comparisons and search operations in the arraylist. Please give me an example.

    Regards,

    Deepak

    Friday, March 1, 2019 6:33 PM

All replies

  • User475983607 posted

    I want to know if there was a maximum limit for values in a 2-dimensional array. Can I declare arr[550000][7] or should I have another way of doing this? Please suggest to me the best  way to increase/decrease an ArrayList hugely and make comparisons and search operations in the arraylist. Please give me an example.

    Post your source code.  Explain the expected results and the actual results.  

    If you are asking a design question, explain what you are trying to do in general. 

    If you need help with the ArrayList object, try reading the documentation.

    https://docs.microsoft.com/en-us/dotnet/api/system.collections.arraylist?view=netframework-4.7.2

    .NET Framework only: For very large ArrayList objects, you can increase the maximum capacity to 2 billion elements on a 64-bit system by setting the enabled attribute of the <gcAllowVeryLargeObjects> configuration element to true in the run-time environment.

    Elements in this collection can be accessed using an integer index. Indexes in this collection are zero-based.

    The ArrayList collection accepts null as a valid value. It also allows duplicate elements.

    Using multidimensional arrays as elements in an ArrayList collection is not supported.

    Friday, March 1, 2019 6:45 PM
  • User1182587605 posted

    Thanks for the reply,

    I wrote a code using lists in CSharp as I can dynamically increase/decrease the array size. I would welcome if I get a final result from the two-dimensional array as well. 

    My requirement is:

    A user will input any 4 Variables Names out of 20.
    The software will show the common sets in all 4 variable.
    The variable type is in a two-dimensional array.

    Variable Name Values
    Variable 1 = ( 2, 4) , ( 5, 1)
    Variable 2 = ( 7, 4) , ( 1, 3)
    Variable 3 = ( 5, 7) , ( 5, 1)
    Variable 4 = ( 2, 4) , ( 2, 1)
    Variable 5 = ( 9, 8) , ( 2, 4)
    Variable 6 = ( 3, 4) , ( 5, 7)
    Variable 7 = ( 4, 7) , ( 4, 2)
    Variable 8 = ( 5, 4) , ( 5, 7)
    Etc….
    (This data will be stored on server.)

    Now for example user give input variable 1, 4, 5, 7
    The calculator will show result =( 2, 4).
    Below is the web layout of the common finder

    my code:

     class Valuegroup
        {
            public int FirsValue { get; set; }
            public int SecondValue { get; set; }
        }
    Dictionary<string, List<Valuegroup>> myList = new Dictionary<string, List<Valuegroup>>();

    With the above declaration we will be able to use the key string Variable 1 , Variable 2 , Variable 3 ect as unique key. Then we can add our values as groups in the List<Valuegroup>. Each list element will represent a group of items such as (2, 4) , (5, 1) etc.
    class Valuegroup
        {
            public int FirsValue { get; set; }
            public int SecondValue { get; set; }
        }
        static void Main(string[] args)
        {
            //Variable 1 = (2, 4) , (5, 1)
    
            Valuegroup first = new Valuegroup
            {
                FirsValue = 2,
                SecondValue = 4
            };
    
            Valuegroup second = new Valuegroup
            {
                FirsValue = 5,
                SecondValue = 1
            };
    
            Dictionary<string, List<Valuegroup>> myList = new Dictionary<string, List<Valuegroup>>();
            myList.Add("Variable 1",new List<Valuegroup>{first,second});
    
            //retrive a value using a key name eg Variable 1
            List<Valuegroup> temp = new List<Valuegroup>();
            myList.TryGetValue("Variable 1", out temp);
    
            //do a search using Linq
            var t = myList.Where(x => x.Key == "Variable 2");
        } 
    My above code results OK but I am looking for an even better solution which accepts large number of collection ex: arr[67000][7] and work efficiently and quickly while performing a search. Any upgrades to the code or modifications are welcome.

    Saturday, March 2, 2019 4:15 PM
  • User1724605321 posted

    Hi acmedeepak ,

    You can refer to below code sample for resize 2D arrays :

    https://stackoverflow.com/a/6539620/5751404 

    But IMO ,  unless you need to micro-optimise, keep the solution simple and use list as you shown.

    Best Regards,

    Nan Yu

    Thursday, March 7, 2019 5:09 AM