có cach nào call tất cả các propertyName trong thuộc tính bằng foreach ko anh nhỉ
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Câu hỏi của bạn có phải là có cách nào để duyệt qua tất cả các property trong 1 object bất kỳ không nhỉ? Nếu đúng như vậy bạn có thể dùng cách sau:
foreach (var prop in obj.GetType().GetProperties())
{
Console.WriteLine(“{0}={1}”, prop.Name, prop.GetValue(obj, null));
}
prop.GetValue(obj) nó trả về 1 list, mình ko thể call list đó ra được, có cách nào call list đó ra ko
Mình chưa hiểu ý bạn lắm. prop.GetValue nó sẽ trả về value của property chứ sao lại trả về 1 list nhỉ?