I have a student class with the following structure:
public sealed class Student
{
public string Name {get;set;}
public string RollNo {get;set;}
public string standard {get;set;}
public bool IsScholarshipped {get;set;}
public List<string> MobNumber {get;set;}
}
How can I get those properties of Student class in an array like
arr[0]=Name;
arr[1]=RollNo;
.
.
.
arr[4]=MobNumber
And the types of these properties in separate array like
arr2[0]=string;
arr2[1]=string;
.
.
.
arr2[4]=List<string> or IEnumerable
Please , explain it with chunk of code.
var type = model.GetType();
var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
That will give you an array of PropertyInfo
. You can then do this to get just the names:
properties.Select(x => x.Name).ToArray();
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