Let's say I have a class called Student
where it has properties of ID
, FirstName
, LastName
. I have a dictionary which stores some information of a particular student.
I want to do something like
var student = new Student();
var studentInfo = new Dictionary<string, string>();
studentInfo["ID"] = "12345";
studentInfo["FirstName"] = "John";
studentInfo["LastName"] = "Doe";
Now I want to assign the key to the attribute of the student. Since the keys of the dictionary are the attribute of the student
. I want to assign the Value of the dictionary to the student depending on the key. Here's my pseudo code.
foreach (var studentInfoItem in studentInfo)
{
student.studentInfoItem.Key = studentInfoItem.Value;
}
Is there any way to do this properly?