[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1676
  • Last Modified:

Foreach in C#

I am new to C#. Not sure what is wrong here.
Error      1      Foreach cannot operate on a 'method group'. Did you intend to invoke the 'method group'?      

namespace Test_Csharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnGetfilename_Click(object sender, EventArgs e)
        {
            DirectoryInfo work_dir = new DirectoryInfo("C:\\Documents and Settings\\test\\Desktop\\test");

            foreach (FileInfo fn in work_dir.GetFiles)
            {
                MessageBox.Show(fn.Name);
            }

        }
    }
}
0
VBdotnet2005
Asked:
VBdotnet2005
  • 2
1 Solution
 
p_davisCommented:
foreach (FileInfo fn in work_dir.GetFiles())
0
 
p_davisCommented:
you forgot the parenthesis for the method call
0
 
VBdotnet2005Author Commented:
thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now