We help IT Professionals succeed at work.
Get Started

How to call a method with List type

Last Modified: 2019-12-31
Hello Experts,
I have a Console App, which imports some data thru an API call.  In this all the methods are defined inside the Main().  I am trying to define some methods such as xxxSearch and XxxxDetail, return type List, outside of the Main() method.  When I do that, I am getting the Error: CS0120 An object reference is required for the non-static field, method, or property 'XxxxImport.XxxxSearch(DateTime, DateTime)'.

The reason I need to do this, because I need to convert this to a Windows Service Program comfortably.

Please let me know how to define them outside of Main() method and call them,

Thank you very much in advance.

Below is the Skeleton of the Code

public static void Main(string[] args)
    DataSet ds = new DataSet();

    var fromDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd")).AddDays(-1);
    var toDate = DateTime.Parse(fromDate.ToString("yyyy-MM-dd")).AddDays(0);

    MainHub(fromDate, fromDate);


    void MainHub(DateTime FromDate, DateTime ToDate)
      var xxxFound = xxxSearch(FromDate, ToDate);

      if (xxxFound != null)
          InsertxxxRaw(xxxFound, FromDate);

      foreach (var xxx in xxxFound)
          var list = new List<string>();

          var details = xxxDetail(xxx.validatingxxxDesignator, list);

          if (details != null)

    IList<Xxxx> xxxSearch(DateTime from, DateTime to)
      IList<Xxxx> searchResults = new List<Xxxx>();

          while (true)
      catch (SqlException ex)

      return searchResults;

    IList<XxxxDetail> XxxxDetail(string yyyCode, List<string> xxxNumber)
      return detailResults;
Watch Question
Senior Software Engineer
Top Expert 2009
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE