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

  • SEARCH
  • Home
  • 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 4598768
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:26:47+00:00 2026-05-21T23:26:47+00:00

I am having one property called Students which is of type List<Student> . In

  • 0

I am having one property called Students which is of type List<Student>.

In reflection i can get the value of Students Property.

Now the problem is How to iterate the List of Students.

I need to check whether StudentID [ some value ] is in that collection.

var collection = studentPro.GetValue(studentObj,null);

//I need to iterate like this,

foreach(var item in collection)
{
     if(item.StudentID == 33)
         //Do stuff
}

Please help me.

  • 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-21T23:26:48+00:00Added an answer on May 21, 2026 at 11:26 pm

    You just need to cast it:

    var collection = (List<Student>) studentPro.GetValue(studentObj,null);
    

    The value returned to you and stored in var is of type object. So you need to cast it to List<Student> first, before trying looping through it.

    RANT

    That is why I personally do not like var, it hides the type – unless in VS you hover on it. If it was a declared with type object it was immediately obvious that we cannot iterate through it.


    UPDATE

    Yes its good. But casting should be
    done with reflection. In reflection we
    dont know the type of List. We dont
    know the actual type of the studentObj

    In order to do that, you can cast to IEnumerable:

    var collection = (IEnumerable) studentPro.GetValue(studentObj,null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a property of int type in my view model which is
I am having one problem with the PHP json_encode function. It encodes numbers as
I am having one Gtk+ and C application in which i want to set
I'm having one hell of a time trying to get my databinding to work
hi forum member I am having one problem with setting the radiofield in the
I'm having trouble accessing some variables in my program. I have one class called
I am having a problem with the speed of accessing an association property with
I have a model called User, and a user has a property relatedUsers, which,
I am having one hell of a time coming up with a decent way
I am having one heck of a hard time trying to figure this out.

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.