.net - 在JToken上进行Is操作编译

标签 .net c#-4.0 compiler-errors

我遇到了一个我不知道为什么会发生的问题,

我的代码检查Jtoken的响应,如果确实存在,它将添加到错误列表中

if (response.Response is JToken jToken)
{
     List<ExceptionDescriptor> exceptions = jToken.ToObject<List<ExceptionDescriptor>>();
     GlobalErrorCatcher.CatchException(exceptions);
}

我的问题是,一开始我构建项目时,它失败了,没有显示任何错误消息,这是通过查看此question并通过将错误消息形式从Build和IntelliSense更改为Build来实现的,我在第57行看到了3个错误
这是if (response.Response is JToken jToken)错误是
) expected
; expected
} expected

当我将代码更改为
JToken jToken = response.Response as JToken;
if (jToken != null)
{

    List<ExceptionDescriptor> exceptions = jToken.ToObject<List<ExceptionDescriptor>>();
                GlobalErrorCatcher.CatchException(exceptions);
}

我没有遇到这个问题,
我的应用程序目标框架是.NET Framework 4.6.1
我究竟做错了什么
.NET不喜欢操作吗?

附言:此问题不会在其他任何计算机上出现

最佳答案

该语法是C#7.1的一项功能,非常非常新。发生故障的计算机可能未安装最新的Visual Studio(或您使用的任何其他编译器),因此它不理解该新语法。

关于.net - 在JToken上进行Is操作编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46528730/

相关文章:

c++ - CImg 的编译错误

c# - 使用字符串实习来减少网络客户端的内存使用

c# - ReactiveUI命令退订

c# - 从值中获取键 - Dictionary<string, List<string>>

c# - LINQ to Lookup 具有不同的项目和计数

python - 我如何将 .py 编译为 .exe?

c# - 使用 ReferenceLoopHandling.Ignore 序列化循环依赖的 ISerializable 对象时抛出 StackOverflowException

c# - 如何将命令行参数传递给 MSI 安装程序

c# - RadioButton ContentStringFormat 不起作用

compiler-errors - VB6-找不到方法或数据成员