【问题标题】:Error in c sharp code [duplicate]cSharp代码中的错误[重复]
【发布时间】:2012-06-15 07:58:08
【问题描述】:

可能重复:
Issue using switch case statement

我目前有这样的代码

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Drawing;
using System.ComponentModel;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Excel;
namespace Excel1
{
    class Program
    {
        static void Main(string[] args)
        //public void ExcelOps()
        {
            //string str;
            Excel.Application xlApp = new Excel.Application();
            Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"D:/WebServiceTemplate.xlsx");
            Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
            Excel.Range xlRange = xlWorksheet.UsedRange;
            int rowCount = xlRange.Rows.Count;
            int colCount = xlRange.Columns.Count;
            int numSheets = xlWorkbook.Sheets.Count;
            //
            // Iterate through the sheets. They are indexed starting at 1.
            //
            for (int sheetNum = 1; sheetNum <=1; sheetNum++)
            {
                Worksheet sheet = (Worksheet)xlWorkbook.Sheets[sheetNum];
                //
                // Take the used range of the sheet. Finally, get an object array of all
                // of the cells in the sheet (their values). 
                //
                object[,] valueArray = (object[,])xlRange.get_Value(XlRangeValueDataType.xlRangeValueDefault);
                //
                // Do something with the data in the array with a custom method.
                //                
                ProcessInput(valueArray);
            }
        }
        public static void ProcessInput()
        {
        }
    }
}

我正在尝试使用自定义方法对数组中的数据做一些事情。当我运行它时,我得到一个错误“方法'ProcessInput'的错误没有重载需要1个参数”

怎么了?我该如何继续并纠正这个问题?

【问题讨论】:

  • 这意味着 ProcessInput 方法在您调用它的位置不可见。它是在哪里定义的?
  • “ProcessInput”在哪里定义?您正在调用它,就好像它是您的程序的成员方法一样。
  • @O.R.Mapper 请立即检查问题
  • @ebad86 请立即检查问题...
  • 您能否为新问题创建新问题,或者以不删除以前问题的方式编辑您的问题? SO 意味着永久资源,明天访问此问题的人将无法弄清楚我们当前的大多数答案所指的内容。谢谢。

标签: c# .net


【解决方案1】:

如果这是一个完整代码,编译器是绝对正确的。

此代码中没有任何 ProcessInput(..); 函数定义。

编辑

查看已编辑的帖子会说你错过了声明你的 ProcessInput 函数,比如 static

    public static void ProcessInput()
    {
       ....
    }

【讨论】:

    【解决方案2】:

    现在(在对您的问题进行编辑之后)问题是您正在调用实例方法(ProcessInput)而没有您的类Program 的实例(Main 是一个静态方法)。

    也将ProcessInput标记为static,以解决问题:

    public static void ProcessInput()
    {
    }
    

    或者,创建一个 Program 类的实例并在其上调用方法:

    Program prg = new Program();
    prg.ProcessInput();
    

    【讨论】:

      【解决方案3】:

      尝试更改为

      public static void ProcessInput()
      {
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-06
        • 2012-09-24
        • 1970-01-01
        • 1970-01-01
        • 2015-03-28
        • 2014-04-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多