开发者

What type of struct/container would you use in this instance?

I am trying to figure out what type of structure or container I should use for a quick project. I need to have an unknown number of sets that will be entered from the GUI (each one will have a name, descr开发者_如何学编程iption, unique ID, priority, and boolean for included). Each set will have an unknown number of strings added to it (also from the GUI). After all of the information has been entered, it will be written out to text files where the name of the set is the name of the folder and one text file in that folder will contain all of the strings associated with that set.

I tried creating a dataset with two related tables, but I couldn't seem to programmatically add the rows to the tables and get the sets to display in my datagridview. Now I'm back to trying to find another way to save the sets in memory and display them on the GUI before saving them to disk.

What would you use?


I would just use a class:

 public class Item
    {
        public string Name { get; set; }
        public string Description { get; set; }
        public int ID { get; set; }
        public int Priority { get; set; }
        public bool Included { get; set; }
        public IList<string> Data { get; set; }
    }

for the UI you would have a IList<Item>

EDIT:

If there has to be no duplicates you can put the set into a Dictionary where the key is the ID field and the value is the Item object. This list will not be ordered, but you can write your own sorting method :

IDictionary<int, Item> listOfData;


How about something like this...

public class TheresasSet {
    public string Name { get; set }
    public string Description { get; set; }
    public int ID { get; set; }
    public int Priority { get; set; }
    public bool Included { get; set; }
    public List<string> StringData { get; private set; }

    public TheresasSet() {
        StringData = new List<string>();
    }
}


Generally I'd recommend using classes, structs should be used when the instance size is less than 16 bytes, which this will not be. Anything bigger and you'll start suffering a minor slow down in performance.

If you're having trouble displaying information you could look at overriding the ToString() method, or provide more details on what's not working in the DataGridView.


You can:

  1. Create a class named for example Set, which has name, description, unique ID, priority, and boolean for included as properties.
  2. Add an extra property to the class, of type List<string>, to store the strings added dinamically.
  3. Have a List<Set> to store the sets.


A collection object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜