Runtime type cast in C#

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: mra (mra_at_discussions.microsoft.com)
Date: 03/21/05


Date: Mon, 21 Mar 2005 10:23:03 -0800

I want to cast an object that I have created from a typename to the
corresponding type. Can anycone tell me how to do this?
Example:
//Here, Create the object of type "MyClass"
object obj=Activator.CreateInstance(strAssemblyName, "MyClass");
//Now, I want to do something like ((MyClass)obj).Method
//Can I do this?



Relevant Pages

  • Re: Runtime type cast in C#
    ... this is is defined by the typename string: ... > If you have a reference to the type, then yes, you can, just cast the ... > that loads and creates the type, you cast the return value to the interface, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Is cast operator unary or binary? How many operands?
    ... I'd say one operator, the cast operator, and two operands: typename ... cast is categorized as an unary operator. ... jacob at jacob point remcomp point fr ...
    (comp.lang.c)