【问题标题】:Variable not declared in the scope, but works ("inference"??)变量未在范围内声明,但有效(“推理”??)
【发布时间】:2018-01-11 19:39:53
【问题描述】:

以下语法适用于 Visual Studio 2017 .NET 4.5 中的项目。 同样的语法不适用于另一台装有 Visual Studio 2015 .NET 4.5 的机器。 我不知道这种语法(对我来说,'eventargs' 在那个范围内不存在)。 C# 中是否有任何更新可能会推断出“eventargs”? 我没有找到任何关于它的...

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (!(value is Telerik.XamarinForms.Input.AutoComplete.SuggestionItemSelectedEventArgs eventArgs))
            throw new ArgumentException("Expected SuggestionItemSelectedEventArgs as value", nameof(value));

        return eventArgs;
    }

【问题讨论】:

标签: c# c#-7.0


【解决方案1】:

这是一个名为 pattern matching 的 C# 7 功能,由 Visual Studio 2017 中的编译器引入。

基本上eventArgs 是用is 表达式声明的。

【讨论】:

  • 感谢@Daniel A. White。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-09-18
  • 2017-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-19
相关资源
最近更新 更多