Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Foreach in C#

Posted on 2010-09-21
3
Medium Priority
?
1,640 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 500 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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

636 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