简体   繁体   中英

Alternative to List<Tuple<Grid, TabItem, int, string, int>>… in C#

I'm trying to find an alternative to List<Tuple<Grid, TabItem, int, string, int>>... , since I need to be able to modify the integers' values or string's value.

I say "alternative" because I don't think it's possible to modify any values in a tuple. I don't want to delete it and create it again with different values.

It looks like you should just create your own class to hold these properties, then you can enforce whatever behavior you want. Tuples are mostly just for simple bundling of objects (usually temporarily). If you want an object to hold all these things, be editiable for certain properties (but not others?) then you should just write a class for it.

class BagOfthings
{
    public Grid Grid {get; private set;}
    public TabItem TabItem {get; private set;}
    public int id {get; private set;}
    public String label {get; set;}
    public int index {get; set;}
}

obviously you should pick variables names that make sense :)

You should probably make a list of structs where you name each of the tuple elements:

struct mytype {
    Grid mygrid;
    TabItem myitem;
    int myint;
    // etc
}

Then use List<mytype> . Of course you should replace all those names with something more meaningful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM