简体   繁体   English

如何将字典传递给 class C#

[英]How do you pass a dictionary into a class C#

The problem: How do I pass the Dictionary from Search.Part2 into Search.Main问题:如何将字典从 Search.Part2 传递到 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.我不能使用上下文关键字“var”,因为它可能只出现在局部变量声明或脚本代码中。 this maybe simple but idk what to put instead of var (or if i can even do it this way)这可能很简单,但不知道该放什么而不是 var (或者如果我什至可以这样做)

Example:例子:

void MyMethod(Dictionary<string,string> dictionary)

For you case对于你的情况

Dictionary<string, string> will be whatever the type Search.part2(input) returns. Dictionary<string, string>将是Search.part2(input)返回的任何类型。


Documentation文档

Please see C# Coding Conventions (C# Programming Guide) , specifically Remarks .请参阅C# 编码约定(C# 编程指南) ,特别是备注 Here is just one sentence, from it:这里只是一句话,来自它:

Implicit typing with the var keyword can only be applied to variables at local method scope.使用 var 关键字的隐式类型只能应用于本地方法 scope 的变量。

See also Passing Parameters (C# Programming Guide)另请参见传递参数(C# 编程指南)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM