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

前端 未结 4 1401
深忆病人
深忆病人 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:02

    readonly is a keyword in C#. It's useful when you want to ensure the value never changes outside a constructor.

    This keyword could be helpful when you're contributing code to a large project and you're worried coworkers might try to change a variable that should never be altered.

    Edit: I'm curious why someone downvoted my answer. Whoever downvoted can you please show my where my answer is wrong? Thanks.

提交回复
热议问题