亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C#錯誤:“非靜態字段,方法或屬性需要對象引用”

C#錯誤:“非靜態字段,方法或屬性需要對象引用”

C#
慕桂英546537 2019-11-19 08:43:07
我有兩個類,一個用于定義算法參數,另一個用于實現算法:第1類(算法參數):using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace VM_Placement{    public static class AlgorithmParameters    {        public static int pop_size = 100;        public static double crossover_rate = 0.7;        public static double mutation_rate = 0.001;        public static int chromo_length = 300;        public static int gene_length = 4;        public static int max_allowable_generations = 400;        static Random rand = new Random();        public static double random_num = rand.NextDouble();    }}第2類(實現算法):using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace VM_Placement{    public class Program    {        public struct chromo_typ        {            public string   bits;            public float    fitness;            //public chromo_typ(){            // bits = "";            // fitness = 0.0f;            //}            chromo_typ(string bts, float ftns)            {                bits = bts;                fitness = ftns;            }        };        public static int GetRandomSeed()        {            byte[] bytes = new byte[4];            System.Security.Cryptography.RNGCryptoServiceProvider rng =              new System.Security.Cryptography.RNGCryptoServiceProvider();            rng.GetBytes(bytes);            return BitConverter.ToInt32(bytes, 0);        }        public string GetRandomBits()        {            string bits="";            for (int i = 0; i < VM_Placement.AlgorithmParameters.chromo_length; i++)            {                if (VM_Placement.AlgorithmParameters.random_num > 0.5f)                    bits += "1";                else                    bits += "0";            }            return bits;        }我對得到一個錯誤Population[i].bits = GetRandomBits();在Main()。錯誤是:非靜態字段,方法或屬性'VM_Placement.Program.GetRandomBits()'需要對象引用。我有什么想念的嗎?
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 769 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號