c# - Why can I not call my function with the calling line of -


Why can not I say like my function as if I have it now? The code works perfectly for PrintDictionary if I have this main method. I want to move it to a function and then want to use it in the same way with my parameter passing, but it gives errors that are listed below.

Question: What have I done to the errors given below when I just want to call a function to print?

  printDictionary (d); & Lt; - Error   

Calling code:

  printDictionary (d);   

To call the function:

  Private Zero printDictionary (dictionary & lt; string; employee & gt; & gt; & gt; & gt; InputDictionaryParm1 from list ) {foreach (in InputDictionaryParm1 a) {Console.WriteLine (a.Key); Foreign (preference in a.value) {Console.WriteLine ("\ t" + e.Name); }} Console. Readkey (); }   

Error table:

  Error 1 'ConsoleApplication1.Program.printDictionary (System.Collections.Generic.Dictionary & lt The best overloaded method Match \ Users \ itpr13266 \ AppData \ Local \ Temporary Projects \ ConsoleApplication1 \ Program.cs 52 13 ConsoleApplication1 Error 2 Argument 1: String, System.Collections.Generic.List & LT; ConsoleApplication1.Employee & gt; & gt; There is such an invalid argument: can not be changed from '; String, System.Collections.Generic.SortedSet & LT; ConsoleApplication1.Employee & gt; Make System.Collections.Generic.SortedDictionary & lt> 'System.Collections.Generic.Dictionary & lt; String, System.Collections.Generic.List & lt; ConsoleApplication1.Employee & gt; & Gt; C: \ Users \ itpr13266 \ AppData \ Local \ Temporary Projects \ ConsoleApplication1 \ Program.cs 52 29 ConsoleApplication1    

After "div class =" text "itemprop =" text ">

By looking at the mistake, you are trying to pass a sorted project in a method that accepts a dictionary. These two types are not identical and they can not be used alternately though they both If applicable, you can choose the method to use the interface instead of a specific class You can change the sign.

You may consider changing the method signature to:

  Private Zero printDictionary (IDictionary & lt; string, ienumerable & lt; employee & gt; & gt; ; InputDictionaryParm1) {foreach (InputDictionaryParm1 in a) {Console.WriteLine (a.Key); Foreign (preference in a.value) {Console.WriteLine ("\ t" + e.Name); }} Console. Readkey (); } I made two changes: switching from idsin and list to IEnumerable from the list does not appear that you are using something specific in the list, so IEnumerable is a better option (if If you need to do then calculate the values).   

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -