Thread: list help

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    9

    list help

    I'm doing a punnett square and putting the output into a list.

    I want to compare the output to the list and if exists; update the count in the list.
    I'm new to C# and don't fully understand lists/collections.

    pseudo code:
    if (color) != (ColorList)
    {append to list}
    else {ColorList (ColorCount)++}


    Code:
    
    namespace Genetics
    
    {           
                   public class Colors{
                    public String Name { get; set; }
                    public int ColorCount { get; set; }
                   }
    
        class Genetics
        {   
            static void Main(string[] args)
            {
                
    int value;            
     var coloList = new List<Colors>();
    
    // Sire & Dam & Offspring Geneotype single dimensional array 
    int[] sire; 
    int[] dam; 
    int[] offspring;
    // columns fields: 0;1= Broken 2;3 = Agouti 4;5 = Brown 6;7 = Colour 8;9=  Dilute 10;11 = Extension 12;13=  Vienna 
    sire = new int[14];
    dam = new int[14];
    offspring = new int[14]; 
      
     // mutiple dimension array 
      const int rows = 128 ;
      const int columns = 7 ; // 0 = En 1 = A 2 = B 3 = C 4 = D 5 = E 6 = V //
      int [,] siredata = new int[rows,columns];
      int [,] damdata = new int[rows,columns];
    
    
    void child_setup()
    // populate offspring array //
    {
       damcounter=0;
       sirecounter=0;
       offspringcounter=0;
    
       While (damcounter  <= 119);
        {
          While (sirecounter <=119);
            {
          REW_setup();
          Vienna_setup();
          Extension_setup();
          Dilute_setup();
          Colour_setup();
          Brown_setup();
          Agout_setup();
          Broken_setup();
          offspring_colour();
    	  offspringcounter++;
          sirecounter++; }
    	  damcounter++; }
    // end loop
    
     return;
    }

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    I think what you're looking for is Dictionary<>:
    Code:
    Dictionary<string, int> colors = new Dictionary<string, int>();
    
    if(!colors.ContainsKey(color))
      colors.Add(color, 1);
    else
      colors[color]++;
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    9
    Thanks.
    That does what I want.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c program that accepts and executes commands?
    By Cimposter in forum C Programming
    Replies: 3
    Last Post: 09-30-2009, 02:58 PM
  2. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM