What are the uses of “using” in C#?

后端 未结 29 2899
有刺的猬
有刺的猬 2020-11-21 07:31

User kokos answered the wonderful Hidden Features of C# question by mentioning the using keyword. Can you elaborate on that? What are the uses of

29条回答
  •  醉话见心
    2020-11-21 07:44

    using can be used to call IDisposable. It can also be used to alias types.

    using (SqlConnection cnn = new SqlConnection()) { /*code*/}
    using f1 = System.Windows.Forms.Form;
    

提交回复
热议问题