Using statement question

后端 未结 6 1022
挽巷
挽巷 2021-01-13 04:03

I have two questions.

1) Should you always use a using statement on a connection? So, I would use it on the connection and then another one on a reader within the c

6条回答
  •  耶瑟儿~
    2021-01-13 04:45

    To answer each one:

    1) Yes, this would be best practice to dispose both as soon as possible.

    2) using() will create two blocks, wrapped in each other in the same order. It will dispose the inner object (the reader) first, then dispose the object from the outer using (the connection).

提交回复
热议问题