Add-Type不支持字典初始化语法吗?

下面的代码得到的错误

  

添加类型:c:\ Users .... cs(7):无效的表达式术语'['

     

c:\ Users ..... cs(6):返回新字典{

     

c:\ Users ..... cs(7):>>> [“ aa”] =“ 123”,

     

c:\ Users ..... cs(8):[“ bb”] =“ 235”

$Source = @"
using System.Collections.Generic;
public class BasicTest
{
  public static Dictionary<string,string> Add(int a,int b)
    {
        return new Dictionary<string,string>{ 
            ["aa"] = "123",["bb"] = "235"
        };
    }
  public int Multiply(int a,int b)
    {
    return (a * b);
    }
}
"@

Add-Type -TypeDefinition $Source
appleapple12 回答:Add-Type不支持字典初始化语法吗?

当我运行<img src='{{ target_img.url }}'> 时,选项之一是:

help Add-Type

.NET 3.5附带的选项最多只能使用C#3.0。它所破坏的语法是使用C#6.0中的功能。

注意:我的Powershell版本是5.1,它随Windows一起提供,并且早于当前的开源Powershell:https://github.com/PowerShell/PowerShell。我敢打赌,您的示例将在更新的版本中使用。

本文链接:https://www.f2er.com/3140357.html

大家都在问