[Solved] How to instantiate objects dynamically in C# [closed]


Keep references to your objects with a list:

        var myobjects = new List<System.Security.Cryptography.MD5>();
        for (var i = 0; i < 100; i++)
        {
            myobjects.Add(System.Security.Cryptography.MD5.Create());
        }

and iterate through the list:

        for (var i = 0; i < 100; i++)
        {
            myobjects[i].ComputeHash(new byte[] { (byte)i });
            Console.WriteLine(BitConverter.ToString( myobjects[i].Hash));
        }

Otherwise Reusing the same variable will make the previous object go out of scope, and dispose itself.

solved How to instantiate objects dynamically in C# [closed]