Solved

Foreach in C#

Posted on 2010-09-21
3
1,498 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
  • 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now