Solved

Foreach in C#

Posted on 2010-09-21
3
1,574 Views
Last Modified: 2013-12-16
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
Comment
Question by:VBdotnet2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 33727678
foreach (FileInfo fn in work_dir.GetFiles())
0
 
LVL 22

Accepted Solution

by:
p_davis earned 125 total points
ID: 33727681
you forgot the parenthesis for the method call
0
 

Author Closing Comment

by:VBdotnet2005
ID: 33727688
thanks
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question