- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
考虑以下代码块:
int x = 1;
D foo = () =>
{
Console.WriteLine(x);
x = 2;
};
x = 3;
foo();
Console.WriteLine(x);
输出是:3,2。我试图了解这段代码运行时幕后发生的事情。
x 变量如何改变的问题。 <>_DiplayClass1 中的 x 如何改变 Program 类中的 x。它在幕后做这样的事情吗?
var temp = new <>c_DisplayClass1();
temp.x = this.x;
temp.<Main>b_0();
this.x = temp.x;
最佳答案
如果您查看 Main
中发生的情况,您会看到:
public static void Main(string[] args)
{
Program.<>c__DisplayClass0_0 <>c__DisplayClass0_ = new Program.<>c__DisplayClass0_0();
<>c__DisplayClass0_.x = 1;
Action action = new Action(<>c__DisplayClass0_.<Main>b__0);
<>c__DisplayClass0_.x = 3;
action();
Console.WriteLine(<>c__DisplayClass0_.x);
}
[CompilerGenerated]
private sealed class <>c__DisplayClass0_0
{
public int x;
internal void <Main>b__0()
{
Console.WriteLine(this.x);
this.x = 2;
}
}
这让事情变得更加清晰。您会看到被提升的 x
成员被设置了两次,一次是 1
,然后是 3
。在 b__0
中,它再次设置为 2
。因此,您会看到实际更改发生在 同一成员 上。这就是关闭变量时发生的情况。 实际变量被提升,而不是它的值。
关于c# - 深入探讨关闭的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31586153/
默认情况下,Android系统在超过N分钟没操作,会自动关屏并进入休眠状态。 实际上,有些项目要求超时不休眠,如果只是针对单个应用程序,我们可以通过电源管理设置状态来实现, 而如果要设置所有应用的超
1、分析 1、最简单的布局:只有一个listview 如果整个页面只有一个listview的话,那么由于listview本身带有滚动效果,所以当加载的数据超过页面显示的范围时,可以通过上下滑动
一个Bug 前几日出现这样一个Bug是一个RuntimeException,详细信息是这样子的: 复制代码 代码如下: java.lang.IllegalArgumentExcept
已知两个链表list1和list,2,各自非降序排列,将它们合并成另外一个链表list3,并且依然有序,要求保留所有节点。 实现过程中,list1中的节点和list2中的节点都转移到了list3中,
php在做后台服务器的时候,经常会遇到这种情况,需要解析来自前台的xml文件,并将数据以xml格式返回,在这种情况下,xml与php中关联数组的转化是非常频繁的事情。比如flex和其他客户端程序与服
命令行方式: 在phpDocumentor所在目录下,输入phpdoc –h会得到一个详细的参数表,其中几个重要的参数如下: -f 要进行分析的文件名,多个文件用逗号隔开 -d 要分析的目录,多
用C/C++扩展PHP的优缺点: 优点: 效率,还是效率 减少PHP脚本的复杂度, 极端情况下, 你只需要在PHP脚本中,简单的调用一个扩展实现的函数,然后你所有的功能都就被扩展实现了 而缺点也是显
Memcached有个stats命令,通过它可以查看Memcached服务的许多状态信息。使用方法如下: 先在命令行直接输入telnet 主机名端口号,连接到memcached服务器,然后再连接成功
通过status命令,查看Slow queries这一项,如果值长时间>0,说明有查询执行时间过长 复制代码代码如下: 以下为引用的内容: mysql> status;
myisam 存储数据有三个文件.MYD,.MYI ,.FRM 数据文件和索引文件分开存储 innodb存储数据有.FRM存放表定义,.ibd(独享表空间),.ibdata(共享表空间).innod
Oracle数据库查看一个进程是如何执行相关的实际SQL语句 复制代码代码如下: SELECT b.sql_text, sid, serial#, osuser, machine &
答案: 在内建数据类型的情况下,效率没有区别; 在自定义数据类型的情况下,++i效率更高! 分析: (自定义数据类型的情况下) ++i返回对象的引用; i++总是要创建一个临时对象,在退
函数 返回值 和 返回引用 是不同的 函数返回值时会产生一个临时变量作为函数返回值的副本,而返回引用时不会产生值的副本,既然是引用,那引用谁呢?这个问题必须清楚,否则将无法理解返回引用到底是个什么概
两年前从网上看到一道面试题:用两个栈(Stack)实现一个队列(Queue)。觉得不错,就经常拿来面试,几年下来,做此题的应该有几十人了。通过对面试者的表现和反应,有一些统计和感受,在此做个小结。
网站提供上存功能,是很多站点经常会有功能,商城,论坛还有常见一些网盘站点。常见互联网上面,我们也是经常听说,某某站点出现上存漏洞,某某开源项目有上存漏洞。 从互联网开始出现动态程序,上存漏洞像幽灵一
概念:XML序列化是将公共字段和属性转化为序列格式(这里指XML),以便存储或传输的过程。反序列化则是从XML中重新创建原始状态的对象. 复制代码 代码如下: &nbs
1、查看實例名時可用 1、服务—SQL Server(实例名),默认实例为(MSSQLSERVER) 或在连接企业管理时-查看本地实例 2、通過注冊表 HKEY_LOCAL_MACHINE/
一 应用规划: ※ 确定功能。 ※ 必须的界面及界面跳转的流程。 ※ 需要的数据及
parse_url (PHP 4, PHP 5) parse_url — 解析 URL,返回其组成部分 说明 array parse_url ( string $url ) 本函数解析一个 URL
自 PHP 5 起,可以很容易地通过在 $value 之前加上 & 来修改数组的元素。此方法将以引用赋值而不是拷贝一个值。 复制代码 代码如下: <?php $arr = arr
我是一名优秀的程序员,十分优秀!