我有下面的代碼,我的問題是,當我引用變量時,它給了我錯誤:對象引用是非靜態字段,方法,或每個變量的屬性。我知道這是與我的公衆詮釋和公共雙重是非靜態的,但我不知道如何解決它。有人能告訴我可能嗎?問題與非靜態字段需要對象引用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace homework3
{
public class Program
{
public int number_of_scores;
public double score, total_score = 0, high_score, low_score, average;
}
class Class1{
static void Main(string[] args){
Console.Write("please enter the number of scores that you
wish to process? ");
Program.number_of_scores = int.Parse(Console.ReadLine());
Console.Write("Please enter score " + 1 + " ");
Program.score = double.Parse(Console.ReadLine());
Program.high_score = Program.score;
Program.low_score = Program.score;
Program.total_score = Program.total_score = Program.score;
for (int i = 2; i <= number_of_scores; i++);
}
}
class class2
{
static void Main(string[] args){
Console.Write("Please enter score " + i + " ");
Program.score = double.Parse(Console.ReadLine());
Program.total_score = Program.total_score + Program.score;
if(Program.score > Program.high_score)
Program.high_score = Program.score;
if(Program.score < Program.low_score)
Program.low_score = Program.score;
}
}
class Class3
{
static void Main(string[] args){
Program.average = Program.total_score/Program.number_of_scores;
Console.WriteLine("you entered " + Program.number_of_scores +
" scores");
Console.WriteLine("The high score is " + Program.high_score);
Console.WriteLine("The low score is " + Program.low_score);
Console.WriteLine("the average score is " + Program.average);
}
}
....我覺得現在啞赫克哈哈哈 – Zi0n1 2013-02-16 03:02:40
學習:-) – 2013-02-16 03:45:16