How to use dynamic memory (auto-growth functionality) in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;

class Program
{
    static void Main() {
        var list = new List<int>(); // Empty List
        
        for (int i = 0; i < 7; i++) // auto-growth (dynamic memory)
            list.Add(i * 2);
            
        foreach (int value in list)
            Console.Write("{0} ", value);  
    }
}




/*
run:

0 2 4 6 8 10 12 

*/

 



answered Aug 5, 2022 by avibootz

Related questions

1 answer 213 views
1 answer 355 views
1 answer 290 views
2 answers 300 views
1 answer 306 views
1 answer 253 views
...