troubleshooting Question

How to call a method with List type

Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya asked on
ASP.NETVisual Basic.NET.NET ProgrammingC#
11 Comments1 Solution146 ViewsLast Modified:
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);

    Environment.Exit(0);


    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>();
          list.Add(xxx.xxxNumber);

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

          if (details != null)
          {
            InsertDetailTableRaw(details);
          }
      }
    }

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

      try
      {
          while (true)
          {
          }
      }
      catch (SqlException ex)
      {
      }

      return searchResults;
    }

    IList<XxxxDetail> XxxxDetail(string yyyCode, List<string> xxxNumber)
    {
      .
      .
      .
      return detailResults;
    }
}
ASKER CERTIFIED SOLUTION
Miguel Oz
Senior Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2009

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros