I'm attempting to add a dictionary property in one of my model classes that has a set list of key value pairs. However, I don't know how to declare this with the {get; set;} syntax that signals this is a model property and not a simple field.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ContosoUniversity.Models
{
public class Profile
{
//classNameID or ID is interpreted by EF as PK.
public int ID { get; set; }
public string UserName { get; set; }
public string Age { get; set; }
public string Location { get; set; }
public string Gender { get; set; }
//How to declare this property with get, set and initialized key/val pairs?
public string Dictionary<string, string> ProfileDetails =
new Dictionary<string, string>()
{
{"HighSchool", ""},
{"UndergraduateSchool", ""},
{"GraduateSchool", ""},
}
}
}
Declare a property and the you can use constructor to initialize it.
public class Profile
{
public Dictionary<string, string> ProfileDetails {get; set;}
public Profile()
{
ProfileDetails = new Dictionary<string, string>()
{
{"HighSchool", ""},
{"UndergraduateSchool", ""},
{"GraduateSchool", ""},
};
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments