While I userstand how get; & set; with simple types such as strings now can more properties like Dictionary be get or set or can they?
I have a small dos programe trying to do this. snippet below.
# User.cs
namespace LDIFMod
{
public class User
{
public string UserHash { get; set; }
public string UserID { get; set; }
public Dictionary<string, string> UserDict { get; set; } <- how to do this???
}
}
and in my Program.cs
var query = from line in File.ReadAllLines(args[0])
let UserRecord = line.Split(',')
select new User()
{
UserHash = UserRecord[2].Trim() +UserRecord[3].Trim(),
UserID = UserRecord[4].Trim(),
UserDict.???? // userDict should contain key = UserRecord[5] & value = UserRecord[9]
}
You will need to first initialize the dictionary in the constructor of the user class. Use the
private setto prevent people from re-initializing the dictionary.Your calling code becomes
This returns one dictionary per query row. if you want all of the rows to share a dictionary you will need to make it static or not store it inside
User. If you do this be aware that linq is delayed execution so the dictionary will not be fully populated until after you fully enumerate the query.I thought I would give a example of how to do it with all of them in a single dictionary.
and here is the query
This is purely from memory without a ide to check for bugs so there could be some errors.