-3

The problem: How do I pass the Dictionary from Search.Part2 into Search.Main

main part is

namespace Search
{
     public class Search1 : Search
     {
         public static void Search1(string[] input)
         {  
             string[] array = Search.part1(input);
             var dictionary = Search.part2(input);
             Search.Main(input, array, dictionary);
             Console.ReadLine();
         }
    }
}

problem is

public static void Main(string[] input, string[] array, 'var' dictionary)

I cant use the contextual keyword 'var' as it may only appear within a local variable declaration or in script code. this maybe simple but idk what to put instead of var (or if i can even do it this way)

Rufus L
  • 36,127
  • 5
  • 30
  • 43
Cat
  • 31
  • 3
  • See [Use of var keyword in C#](https://stackoverflow.com/questions/41479/use-of-var-keyword-in-c-sharp) – ProgrammingLlama Oct 16 '19 at 00:38
  • 2
    Use the actual type instead of `var`, then. `var` is just syntactical sugar over the actual type. It appears that it would be the same type that `Search.part2` returns. – Rufus L Oct 16 '19 at 00:41

1 Answers1

0

Example:

void MyMethod(Dictionary<string,string> dictionary)

For you case

Dictionary<string, string> will be whatever the type Search.part2(input) returns.


Documentation

Please see C# Coding Conventions (C# Programming Guide), specifically Remarks. Here is just one sentence, from it:

Implicit typing with the var keyword can only be applied to variables at local method scope.

See also Passing Parameters (C# Programming Guide)

Community
  • 1
  • 1
tymtam
  • 31,798
  • 8
  • 86
  • 126