久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 try { return x; 中真正發(fā)生了什么?} 最后 { x = n

What really happens in a try { return x; } finally { x = null; } statement?(在 try { return x; 中真正發(fā)生了什么?} 最后 { x = null;} 陳述?)
本文介紹了在 try { return x; 中真正發(fā)生了什么?} 最后 { x = null;} 陳述?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我在另一個問題中看到了這個提示,想知道是否有人可以向我解釋這到底是如何工作的?

I saw this tip in another question and was wondering if someone could explain to me how on earth this works?

try { return x; } finally { x = null; }

我的意思是,finally 子句真的執(zhí)行 after return 語句嗎?這段代碼有多線程不安全?你能想到任何可以做的額外黑客行為嗎?這個 try-finally 破解?

I mean, does the finally clause really execute after the return statement? How thread-unsafe is this code? Can you think of any additional hackery that can be done w.r.t. this try-finally hack?

推薦答案

不 - 在 IL 級別,您不能從異常處理塊內(nèi)部返回.它本質(zhì)上將它存儲在一個變量中,然后返回

No - at the IL level you can't return from inside an exception-handled block. It essentially stores it in a variable and returns afterwards

即類似于:

int tmp;
try {
  tmp = ...
} finally {
  ...
}
return tmp;

例如(使用反射器):

static int Test() {
    try {
        return SomeNumber();
    } finally {
        Foo();
    }
}

編譯為:

.method private hidebysig static int32 Test() cil managed
{
    .maxstack 1
    .locals init (
        [0] int32 CS$1$0000)
    L_0000: call int32 Program::SomeNumber()
    L_0005: stloc.0 
    L_0006: leave.s L_000e
    L_0008: call void Program::Foo()
    L_000d: endfinally 
    L_000e: ldloc.0 
    L_000f: ret 
    .try L_0000 to L_0008 finally handler L_0008 to L_000e
}

這基本上聲明了一個局部變量(CS$1$0000),將值放入變量中(在處理的塊內(nèi)),然后在退出塊后加載變量,然后返回它.反射器將其呈現(xiàn)為:

This basically declares a local variable (CS$1$0000), places the value into the variable (inside the handled block), then after exiting the block loads the variable, then returns it. Reflector renders this as:

private static int Test()
{
    int CS$1$0000;
    try
    {
        CS$1$0000 = SomeNumber();
    }
    finally
    {
        Foo();
    }
    return CS$1$0000;
}

這篇關(guān)于在 try { return x; 中真正發(fā)生了什么?} 最后 { x = null;} 陳述?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Is there a way to know if someone has bookmarked your website?(有沒有辦法知道是否有人為您的網(wǎng)站添加了書簽?)
Use of Different .Net Languages?(使用不同的 .Net 語言?)
Is there a C# library that will perform the Excel NORMINV function?(是否有執(zhí)行 Excel NORMINV 函數(shù)的 C# 庫?)
Determining an #39;active#39; user count of an ASP.NET site(確定 ASP.NET 站點(diǎn)的“活動用戶數(shù))
Select x random elements from a weighted list in C# (without replacement)(從 C# 中的加權(quán)列表中選擇 x 個隨機(jī)元素(無需替換))
Best way to keep track of current online users(跟蹤當(dāng)前在線用戶的最佳方式)
主站蜘蛛池模板: 国产精品久久久久不卡 | 久久久久久国产精品 | 99精品免费久久久久久久久日本 | 欧美电影免费观看高清 | 视频一区在线观看 | 亚洲精品视频在线播放 | 欧美一级高清片 | 亚洲精品3 | 亚洲欧美日韩精品 | 国产精品自产拍在线观看蜜 | 999国产精品视频 | 亚洲精品毛片av | 在线成人精品视频 | v片网站| 精品福利一区二区三区 | 国产日韩欧美一区 | 亚洲精品电影在线观看 | 欧美福利久久 | 国产草草视频 | 久久综合一区二区三区 | 在线观看精品视频网站 | 欧美激情亚洲 | 不卡一二三区 | 国产成人免费观看 | 成人福利在线视频 | 四虎永久在线精品免费一区二 | 成人免费视频网址 | 欧美自拍第一页 | 欧美一区成人 | 97国产精品| 中文字幕欧美一区 | 国产视频一区在线观看 | 日韩中文视频 | 九色视频网站 | 亚洲最大的黄色网址 | 久久久精品久 | 2018天天干天天操 | 精品视频在线播放 | 91短视频网址| 久一精品 | 色黄网站|