C#6.0的TryParse与出VAR参数 [英] C# 6.0 TryParse with out var param

查看:189
本文介绍了C#6.0的TryParse与出VAR参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#6.0新特性允许申报的TryParse方法内变量。
我有一些代码:

 字符串s =你好; 

如果(int.TryParse(S,出VAR结果))
{

}

不过,我收到编译错误:



我做错了什么?
PS:在项目设置C#6.0和.NET Framework 4.6的设置


解决方案

在C#6.0新特性允许申报的TryParse
方法中的变量。




宣言表达式从C#6.0切在最终版并没有出货。目前,您不能这样做。 有它的C#7(见的:// github上.COM / DOTNET /罗斯林/问题/ 6183>此备查)。


A new feature in C# 6.0 allows to declare variable inside TryParse method. I have some code:

string s = "Hello";

if (int.TryParse(s, out var result))
{

}

But I receive compile errors:

What I am doing wrong? P.S.: in project settings C# 6.0 and .NET framework 4.6 are set.

解决方案

A new feature in C# 6.0 allows to declare variable inside TryParse method.

Declaration expressions was cut from C# 6.0 and wasn't shipped in the final release. You currently can't do that. There is a proposal for it on GitHub for C# 7 (also see this for future reference).

这篇关于C#6.0的TryParse与出VAR参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆