[英]Is it possible to make a “class” runtime?
對於網站的后端,我需要從數據庫中獲取某些數據列,具體取決於用戶擁有的網站設置。 因此,無法預先知道我將需要哪些列。
有什么辦法可以使“對象”列表僅包含返回前端所需的不同類型?
例如:
班級學生存儲在數據庫中:
Students
{
string name;
int age;
double averageGrade;
string class;
Student bestFriend;
}
假設網站上的用戶只想看到學生的姓名和最好的朋友,我如何將它們放在一個對象中,然后將這些對象放在列表中?
exampleStudent {name, bestFriend};
提前致謝!
一種解決方案是使用字典存儲屬性:
Dictionary<string, object> student = new Dictionary<string, object>();
student["name"] = "Alex";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.