I'm reading information from an XML which contains the type of an object that I need to instantiate along with it's constructor parameters.
The object type is actually in another project, within a sibling namespace. (I need to create a Company.Project2.Type within Company.Project1 class.)
I found this question, but it doesn't handle the constructor parameters or the fact that it's in another namespace.
How can I do this?
Edit: The assembly name and default namespace wasn't set correctly in the project properties.
By new keyword : Java String is created by using a keyword “new”. For example: String s=new String(“Welcome”); It creates two objects (in String pool and in heap) and one reference variable where the variable 's' will refer to the object in the heap.
C# also allows verbatim string interpolation, for example across multiple lines, using the $@ or @$ syntax. To interpret escape sequences literally, use a verbatim string literal. An interpolated verbatim string starts with the $ character followed by the @ character.
Example: Create string in C# Note: A string variable in C# is not of primitive types like int , char , etc. Instead, it is an object of the String class.
An instance field, in C#, is a variable of any type contained within a class or struct, and is used to store object data. It is a member of its containing type with one copy of the field for each instance of the containing type.
Type.GetType()
, including namespace, e.g. "Company.Project2.Type"Company.Project2.dll
, you might specify "Company.Project2.Type, Company.Project2".Activator.CreateInstance(Type, Object[])
or get the exact constructor you want with Type.GetConstructor()
and then call ConstructorInfo.Invoke()
.If that doesn't help, please give more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With