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 223 views
1 answer 356 views
1 answer 292 views
2 answers 307 views
1 answer 309 views
1 answer 256 views
...