c# - Matching specific entries in lists -


currently i'm trying write csv exporter utility work speed process of creating work orders our supervisors. on paper it's quite simple concept, import csv containing our part information , our current production requirements. columns of csv being split separate lists. i'm trying create button allow user automatically set quantity based on part number.

the way i'm thinking doing grabbing specific entry on list's 'spot' (can't think of better term).

example:

dinosaur list  1. t-rex  2. triceratops  3. allosaurus  diet list  1. carnivore  2. herbivore  3. carnivore 

if user selected allosaurus, want value returned of 3, , use grab right entry second list, in case, carnivore.

i'm not sure how go doing this, , or direction appreciated.

you should use object-oriented programming in case.

if you, i'd declare class dinosaur, , make subclasses each type of dinosaur. in super class (dinosaur), put abstract property of type dinosaurdiet force subclasses implement property. here's bit of code explain i'm saying:

enum dinosaurdiet //the enumeration types of diet {     carnivore,     herbivore }  abstract class dinosaur //abstract meaning can't instanciated, , serves superclass {     public abstract dinosaurdiet diet { get; } }  class trex : dinosaur {     public override dinosaurdiet diet { { return dinosaurdiet.carnivore; } } }  class triceratop : dinosaur {     public override dinosaurdiet diet { { return dinosaurdiet.herbivore; } } }  class allosaurus : dinosaur {     public override dinosaurdiet diet { { return dinosaurdiet.carnivore; } } } 

once have that, can make list of them , them using index. here's how:

list<dinosaur> dinos = new list<dinosaur>();  dinos.add(new trex()); dinos.add(new triceratop()); dinos.add(new allosaurus());  //get 2nd dinosaur list (0-based) int index = 1; dinosaur d = dinos[index]; 

make sure test index >= 0 && index < dinos.count avoid exception when trying element @ out-of-bound index.


Comments