You can use the following code to create object from a class which name is provided by the user in program run time.
Type type = Type.GetType("Employee");
object instance = Activator.CreateInstance(type);
just for reference sharing the URL of the static class Activator which is part of system namespace.
https://learn.microsoft.com/en-us/dotnet/api/system.activator?view=net-7.0
No comments:
Post a Comment