Monday, December 7, 2015

Alternative Short Syntax For Last Anonymous Objective Variables Scope in C#

using namespace System.Windows.Forms;
    using(var od = new OpenFileDialog())
        {
            if (od.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // TO DO something futher   
            }
        }

------------------------

using namespace System.Windows.Forms;
   if((new OpenFileDialog()).ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                 // Reference to anonymous ShowDialog out of scope    
            }
        }

No comments:

Post a Comment