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 126 views
1 answer 270 views
1 answer 192 views
2 answers 174 views
1 answer 229 views
1 answer 162 views
...