C#对象引用问题

标签 c#

我正在创建一个非常基本的程序,它有一个填充数组的方法,但我收到一个我不明白的错误。我是一名试图适应 C# 和 .NET 的 Java 程序员。任何帮助都会很棒。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace TestThreads
{
    class Program
    {
        static void Main(string[] args)
        {
             int[]  empty = new int[50001];
             int[] filled = new int[50001];

            filled = compute(empty); //error occurs here

            Console.ReadLine();
        }

        public int[] compute(int[] inArray)
        {
            for (int i = 0; i < inArray.Length; i++)
            {
                inArray[i] = i << 2;
            }

            return inArray;
        }
    }
}

错误信息:

错误 1 ​​非静态字段、方法或属性需要对象引用 'TestThreads.Program.compute(int[])' C:\Users\hunter.mcmillen\Desktop\TestProcessSplitting\TestProcessSplitting\Program.cs 17 22 测试线程

谢谢, 猎人

最佳答案

计算方法应该是静态的。

public static int[] compute(int[] inArray)

关于C#对象引用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6228675/

相关文章:

c# - C# 中的高精度整数数学?

c# - 当键从不冲突时快速并行添加到字典

c# - 在C#中,每次都会评估循环声明吗?

c# - 跟踪工作簿和工作表重命名

c# - Unity 失真音频

c# - 如何在c#中显示括号之间的线

c# - OpenCover 测试工具在 Visual Studio 2013 中的使用

c# - 如何确定 Entity Framework 对象是否已更改?

c# - 在命令文本中设置 ANSI_NULLS 会出现错误

c# - 将二维数组转换为列表(一维)的快速方法