jkj2000
jkj2000

Reputation: 1603

Getting actual type from generic type

I'm wondering if this is possible. I have a generic class that looks like so:

public class SomeClass<T> : SomeInterface
{
    public SomeClass()
    {
      var someVariable = new OtherClass("string_parameter");
    }
}

What I'd like to do is use that generic parameter in my OtherClass constructor, sort of like OtherClass(T.GetType().ToString()) but am having no luck. Is what I'm after possible, or can I not get at the T parameter in that fashion?

Upvotes: 0

Views: 57

Answers (1)

SLaks
SLaks

Reputation: 888223

You're looking for typeof(T).Name

Upvotes: 3

Related Questions