小编fil*_*pot的帖子

尝试捕捉性能 c#

我对 try catch 的了解有限。但我想知道它是否可以用来获得性能。

例如,我正在创建这个体素引擎,其中一个函数是这样的:

Block GetBlockInChunk(Vector Position){
    if(InBound(Position)){
        return Database.GetBlock();
    }
    return null;
}
Run Code Online (Sandbox Code Playgroud)

这里它必须检查给定位置的边界,使用try catch,然后你可以删除它们吗?

Block GetBlockInChunk(Vector Position){
    try{
        return Database.GetBlock();
    }
    catch{
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

我觉得这可能是可怕的做法,但我很好奇。

c# performance try-catch

1
推荐指数
1
解决办法
2541
查看次数

标签 统计

c# ×1

performance ×1

try-catch ×1