Wednesday, January 4, 2023

Create a object of class in c# from string input dynamically from user

 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

ASP.NET Core

 Certainly! Here are 10 advanced .NET Core interview questions covering various topics: 1. **ASP.NET Core Middleware Pipeline**: Explain the...