Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 存储用户提供的值_C#_Methods_Storing Data - Fatal编程技术网

C# 存储用户提供的值

C# 存储用户提供的值,c#,methods,storing-data,C#,Methods,Storing Data,我试图存储用户提供的值,以便计算分配的总和和平均值。我可以打印值,但不能存储它们 我不是在寻找答案,只是在寻求指导 感谢您的回复 public class average { public int num; public double avg; public average() { } // no argument method public average(int nums, double avgt) { num = nums;

我试图存储用户提供的值,以便计算分配的总和和平均值。我可以打印值,但不能存储它们

我不是在寻找答案,只是在寻求指导

感谢您的回复

public class average {
    public int num;
    public double avg;        

    public average() { } // no argument method
    public average(int nums, double avgt) {
        num = nums;
        avg = avgt;
    }
    public int Num {
        get { return num; } // used to get the contents from the main()
        set { num = value; }
    }
    public double Avg {
        get { return avg; }
        set { avg = value; }
    }
    public void print_info() { // prints the final results of code
                               // Cannot get the values to store properly
        Console.WriteLine("The average is {0}, the sum of 10 numbers is {1}", (avg/10),num);
        Console.WriteLine("Press any key to continue . . .");
        Console.ReadLine();
    }   

    {class assignment1 // wrapper class for main
        static void Main(string[] args) {
            int num0;
            int val;

            int nums = 0;
            double avgt = 0.0;

            average num1 = new average(nums, avgt);
            for (val = 0; val < 10; val++) { // loop for user input
                Console.Write("Enter an integer value: ");
                num0 = Convert.ToInt32(Console.ReadLine());  
            }
            num1.print_info(); // calls print_info() method
        }
    }
}
公共类平均值{
公共整数;
公共双平均值;
public average(){}//无参数方法
公共平均值(整数单位,平均双倍){
num=nums;
平均值=平均值;
}
公共整数{
get{return num;}//用于从main()获取内容
设置{num=value;}
}
公共双平均值{
获取{return avg;}
设置{avg=value;}
}
public void print_info(){//打印代码的最终结果
//无法获取要正确存储的值
WriteLine(“平均值为{0},10个数字之和为{1}”,(avg/10),num);
Console.WriteLine(“按任意键继续…”);
Console.ReadLine();
}   
{class assignment1//main的包装类
静态void Main(字符串[]参数){
int num0;
int-val;
int nums=0;
双avgt=0.0;
平均num1=新平均值(nums,平均值);
对于(val=0;val<10;val++){//用户输入循环
编写(“输入整数值:”);
num0=Convert.ToInt32(Console.ReadLine());
}
num1.print_info();//调用print_info()方法
}
}
}

在..中读取num0后,您不会对其执行任何操作。。。。。也许你想要更新一些东西,一旦你有了它?顺便说一句,这个问题很可能会被关闭,因为这是一个非常糟糕的问题stackoverflow。别生气。我该怎么问呢?在这个网站上有没有一个地方可以让我找到如何提问的方法。谢谢你想用另一个类来做这件事吗?:)在循环中,您将分配给
num0
,然后。。。不要用它。我同意你的逻辑是错误的,但是如果你不想得到一个明确的答案,你应该想想
num0
的目的是什么,以及
average
的目的是什么,以及如果两者从不沟通,它们是否可能正常工作。