Thread: No overload for method 'this' takes 2 arguments error

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    20

    No overload for method 'this' takes 2 arguments error

    I'm trying to parse an element of a string array to an int.

    Code:
      public static void child_calc()
            {
               
    
    
                if (jw.totalcount == hk1Class.rows)
                { jw.linked = true; }
    
    
                if (jw.linked == true)
                {
                    linkedClass.linked_parent_setup();
    
    
                      // clone dictionary to enable converting to array
                        Dictionary<string, int> childcolor1 = new Dictionary<string, int>();
                        Dictionary<string, int> colorscopy = new Dictionary<string, int>(childcolor1);
    
    
                    // convert dictionary to array
                        int[] values = childcolor1.Values.ToArray();
                        string[] keys = childcolor1.Keys.ToArray();
    
    
                    // clone dictionary to enable converting to array
                        Dictionary<string, string> childgeneo1 = new Dictionary<string, string>();
                        Dictionary<string, string> geneocopy = new Dictionary<string, string>(childgeneo1);
                    // convert dicitionary to arry
                        string[] keys1 = childgeneo1.Keys.ToArray();
                        string[] values1 = childgeneo1.Values.ToArray();
    
    
    
    
                   // setting up the print parameters
                    int z = 0; //local var
                    while (z < (jw.totalcount + 1))
                    {
                        // calculate color type %
                        string dz = childcolor1[z, 1]; // copy array value to local string
                        int colorpct1 = Int32.Parse(dz); // copys  array value to local int
                        colorpct1 = ((colorpct1 / jw.totalcount) * 100); // converts to a percentage
                        jw.colorpct = colorpct1; // converts the int to a string so % sign can be appended
    
    
                        // append % to end of string
                        string pct2 = "%";
                        jw.colorpct += pct2;
                         
                       
                        // print to screen 
                        Console.WriteLine("{0}, {1}, {2},",
                           childcolor1[z, 0],
                           childgeneo1[z, 0],
                           jw.colorpct);
                    } // end while
    
    
                } // end if 
            
                return;
            } // end child_calc
    this line is throwing the no overload error:
    Code:
     string dz = childcolor1[z, 1]; // copy array value to local string
    My end result is to have converted 'string dz' to an int.
    What am I missing?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Dictionary<string, int> should be indexed with one string, you're trying to index it with two integers.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    Furthermore you're trying to assign the resulting integer to the String dz.

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    20
    I'm just not seeing
    Can you please show what in my code is wrong and the proper way to do it.

    My train of thought was that since I converted to an array; I could treat it like a normal 2d array.

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    129
    woah. foreach a keyvaluepair instead of all that.
    He who asks is a fool for five minutes, but he who does not ask remains a fool forever.

    The fool wonders, the wise man asks. - Benjamin Disraeli

    There are no foolish questions and no man becomes a fool until he has stopped asking questions. Charles Steinmetz

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You're converting the keys and values separately from the dictionary, which creates 2 1-dimensional arrays, not 1 2-dimensional array.

    Also:
    Code:
    jw.colorpct = colorpct1; // converts the int to a string so % sign can be appended
    This isn't right either. You can't just assign an int to a string to make it convert it.

    I'm not sure what the heck your dictionaries are supposed to contain, but it definitely looks like you're doing things the hard way.
    If you understand what you're doing, you're not learning anything.

  7. #7
    Registered User
    Join Date
    Nov 2011
    Posts
    20
    Dictionary childcolor1 the key is color name and the value is how many.
    Dictionary chidgeneo1 the key is geneotype and value is color name.

    I need to output to screen color name, corresponding geneotype, (chlidcolor1 value as a %) on 1 line.

    I google and see how to foreach keyvaluepair into a list. I'm just not seeing/grasping how to do that into a 2d array.

    As for assigning the int to a string; I'm scrapping that and will instead print % behind the value.

  8. #8
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    I don't see why you're so stuck on 2d arrays. The dictionary lets you do all the lookups.
    Code:
            static void Main(string[] args)
            {
                Dictionary<string, int> colorAmounts = new Dictionary<string, int>();
                colorAmounts.Add("green", 4);
                colorAmounts.Add("red", 12);
                colorAmounts.Add("blue", 7);
    
                Dictionary<string, string> geneotypes = new Dictionary<string, string>();
                geneotypes.Add("fluffy", "green");
                geneotypes.Add("bunny", "red");
                geneotypes.Add("feet", "blue");
    
                int totalChildren = colorAmounts.Sum(c => c.Value);  // 4 + 12 + 7 in this example
    
                foreach (string type in geneotypes.Keys)
                {
                    string color = geneotypes[type];
                    Console.WriteLine("Geneotype: {0}, Color: {1}, Percent: {2}%", type, color, (double)colorAmounts[color] / totalChildren * 100);
                }
            }
    Code:
    Geneotype: fluffy, Color: green, Percent: 17.3913043478261%
    Geneotype: bunny, Color: red, Percent: 52.1739130434783%
    Geneotype: feet, Color: blue, Percent: 30.4347826086957%
    Press any key to continue . . .
    If you understand what you're doing, you're not learning anything.

  9. #9
    Registered User
    Join Date
    Jun 2003
    Posts
    129
    Doing this on an iPhone is not easy as I thought... Excuse the case and any rough typos...

    Code:
    Dictionary<string, string> listA = new dictionary<string, string>();
    Dictionary<string, int> listB = new dictionary<string, int>();
    
    Foreach(keyvaluepair kvp in listA)
    {
    console.writeline(kvp.key + kvp.value + " " + listB[kvp.value].tostring());
    }
    Pretty easy to pull the data this way, once you have two dictionaries that share a common value I'm sure you would be better off building a custom class and make it into a list of your own using generics.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Arguments return method is not working for float
    By girish1026 in forum C Programming
    Replies: 3
    Last Post: 09-23-2010, 01:26 AM
  2. trouble with arguments in main method
    By vopo in forum C Programming
    Replies: 3
    Last Post: 07-15-2007, 10:14 PM
  3. Replies: 9
    Last Post: 01-02-2007, 04:22 PM
  4. Takes 0 arguments?
    By 7smurfs in forum C# Programming
    Replies: 1
    Last Post: 12-23-2004, 12:19 PM
  5. Replies: 2
    Last Post: 05-05-2002, 09:27 AM