Why is a variable declared in a using statement treated as readonly?

前端 未结 4 1409
深忆病人
深忆病人 2020-12-20 23:48

Why using variable treated as readonly? It is c# language specification or managed languages specification? It is because c# is a .net language? Thanks in advan

4条回答
  •  清酒与你
    2020-12-21 00:11

    If you mean the variable instantiated at the start of a using block, then it's read only because it needs to be disposed at the end of the block. The point of a using block is to have a resource destroyed in a predictable way rather than waiting for the garbage collector to do it's job.

提交回复
热议问题