English 中文(简体)
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, description, 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?

最佳回答

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>();
    }
}
问题回答

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;

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.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签