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

后端 未结 29 2898
有刺的猬
有刺的猬 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:48

    public class ClassA:IDisposable
    
    {
       #region IDisposable Members        
        public void Dispose()
        {            
            GC.SuppressFinalize(this);
        }
        #endregion
    }
    

    public void fn_Data()
    
        {
         using (ClassA ObjectName = new ClassA())
                {
                    //use objectName 
                }
        }
    

提交回复
热议问题