Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4619896
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:29:11+00:00 2026-05-22T02:29:11+00:00

List<MyClass> MyClassPro { get;set; } MyClass obj = new MyClass(); obj.MyClassPro = null; Consider

  • 0
List<MyClass> MyClassPro
{
   get;set;
}

MyClass obj = new MyClass();

obj.MyClassPro = null;

Consider the MyClassPro is null. In situation of Reflection i wont be knowing the Classname or Property Name.

If i try to get the Type of property using GetType like ,

      Type t = obj.GetType();

It is returning “System.Collections.Generic.list. But my expectation is to get the Type as MyClass.

I also tried the way like

        foreach(PropertyInfo propertyInfo in obj.GetProperties())
        {
             if(propertyInfo.IsGenericType)
             {
              Type t = propertyInfo.GetValue(obj,null).GetType().GetGenericArguments().First();
             }
        }

But it is returning error because of the Value of the collection property is null so we cant get the Type.

In this situation how can i get the Type of a collection Property.

Please help me !

Thanks in Advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:29:12+00:00Added an answer on May 22, 2026 at 2:29 am

    Use propertyInfo.PropertyType instead of propertyInfo.GetValue(obj,null).GetType() which should give you the property type even if the property value is null.

    So when you have a class like

    public class Foo {
        public List<string> MyProperty { get; set; }
    }
    

    and an instance of Foo in obj, then

    var propertyInfo = obj.GetType().GetProperty("MyProperty"); // or find it in a loop like in your own example
    var typeArg = propertyInfo.PropertyType.GetGenericArguments()[0];
    

    will give you the value System.String (as a System.Type instance) in typeArg.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming these objects... class MyClass { int ID {get;set;} string Name {get;set;} List<MyOtherClass> Things
I have a List where MyClass has a property 'Name'. I want to know
Hi i have a List where myclass have a name property, nothing fancy (for
If I have a list... dim l as List(of MyClass) = new List(of MyClass)
For example: List<MyClass> myList = new List<MyClass>(); ... // add lots of members... ...
I have a class like this: public class myClass { public List<myOtherClass> anewlist =
I'd like something like int minIndex = list.FindMin(delegate (MyClass a, MyClass b) {returns a.CompareTo(b);});
MyClass[] array; List<MyClass> list; What are the scenarios when one is preferable over the
I'm de/serializing an object like so: public class myClass : ISerializable { public List<OType>
List<String> nameList = new List<String>(); DropDownList ddl = new DropDownList(); List is populated here,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.