博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#匿名方法返回值赋值给变量
阅读量:5086 次
发布时间:2019-06-13

本文共 1059 字,大约阅读时间需要 3 分钟。

The problem here is that you've defined an anonymous method which returns a string but are trying to assign it directly to a string. It's an expression which when invoked produces a string it's not directly a string. It needs to be assigned to a compatible delegate type. In this case the easiest choice is Func
Func
temp = () => {return "test";};This can be done in one line by a bit of casting or using the delegate constructor to establish the type of the lambda followed by an invocation.string temp = ((Func
)(() => { return "test"; }))();string temp = new Func
(() => { return "test"; })();Note: Both samples could be shorted to the expression form which lacks the { return ... }Func
temp = () => "test";string temp = ((Func
)(() => "test"))();string temp = new Func
(() => "test")();

 

posted on
2016-05-03 16:49 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/lonelyxmas/p/5455612.html

你可能感兴趣的文章
对象与类
查看>>
《奸的好人2》财色战场----笔记
查看>>
BZOJ 1834网络扩容题解
查看>>
bzoj1878
查看>>
【Vegas原创】Mysql绿色版安装方法
查看>>
Thrift Expected protocol id ffffff82 but got 0
查看>>
.NET下XML文件的读写
查看>>
2009程序员考试大纲
查看>>
Linq to XML
查看>>
[HDOJ3718]Similarity(KM算法,二分图最大匹配)
查看>>
Nexus Repository3安装和maven,npm配置(Linux)
查看>>
a 标签中调用js的几种方法
查看>>
从SQL Server 2005 中 导入 导出 excel 表格
查看>>
R Shiny(开源的R包)
查看>>
用Tensorflow做蝴蝶检测
查看>>
Hbuilder编辑器 设置less即时编译环境
查看>>
Spring Cloud 入门教程(六): 用声明式REST客户端Feign调用远端HTTP服务
查看>>
Spring Cloud 入门教程(一): 服务注册
查看>>
【2.2】创建博客文章模型
查看>>
【3.1】Cookiecutter安装和使用
查看>>