C# 使用数组返回值

C# 使用数组返回值,c#,arrays,visual-studio,parameters,return-value,C#,Arrays,Visual Studio,Parameters,Return Value,我对编程很陌生,我只是需要帮助来解决我做错了什么 这是我目前掌握的代码。是的,这是家庭作业,但我不知道下一步要做什么 在createRandomlyFilleArray方法中,我必须创建一个分配的数组。此方法将接受一个整数作为其唯一参数,然后在该方法内创建数组,数组中填充由该方法随机创建的值。(值可以是0到100) 然后将数组作为参数传递给printary方法,printary方法将整数数组作为其单个参数,并将打印出数组中的所有内容 class Returning_An_Array {

我对编程很陌生,我只是需要帮助来解决我做错了什么

这是我目前掌握的代码。是的,这是家庭作业,但我不知道下一步要做什么

在createRandomlyFilleArray方法中,我必须创建一个分配的数组。此方法将接受一个整数作为其唯一参数,然后在该方法内创建数组,数组中填充由该方法随机创建的值。(值可以是0到100)

然后将数组作为参数传递给printary方法,printary方法将整数数组作为其单个参数,并将打印出数组中的所有内容

class Returning_An_Array
{
    public void RunExercise()
    {
        ArrayReturnMethods m = new ArrayReturnMethods();
        int[] nums1; 
        nums1 = m.CreateRandomlyFilledArray(10);          

        m.PrintArray(nums1);
    }
}

class ArrayReturnMethods
{

    public int[] CreateRandomlyFilledArray( int size )
    {
        int[] newNums = new int[size];
        for (int value = 0; value < newNums.Length; value++)
        {
            return newNums;

        }
        return newNums;

    }

    public void Printarray( int[] value )
    {
        for(int i = 0; i < value.Length; i++)
        {
            Console.WriteLine("value is: {0}", value[i]);
        }
    }
}
类返回一个数组
{
公开演习(
{
ArrayReturnMethods m=新的ArrayReturnMethods();
int[]nums1;
nums1=m.createRandomlyFilled阵列(10);
m、 打印阵列(nums1);
}
}
类ArrayReturnMethods
{
公共int[]CreateRandomlyFilled阵列(int大小)
{
int[]newNums=newint[size];
for(int值=0;值

非常感谢你

避免在这里问家庭作业问题。特别是当一点阅读就能解决你的问题时。祝你作业顺利。:)

类程序
{
/*
我想你是想
1.创建一个整数数组
2.在该数组中存储随机数(0到100之间)
3.打印数组中的数字
你有很多阅读要做,因为在你的方法和代码中都有很多基本的错误。
*/
静态void Main(字符串[]参数)
{
//使用随机数创建数组
ArrayMethods m=新的ArrayMethods();
int[]nums1;
nums1=m.createRandomlyFilled阵列(10);
m、 打印阵列(nums1);
}
类数组方法
{
/*
-首先,必须用随机数填充数组
在解决方案中,您创建了“CreateRandomlyFilleArray”。
1.您创建了一个新的整数数组,这很好
2.尝试填充新数组的方式不正确
*/
公共int[]CreateRandomlyFilled阵列(int大小)
{
int[]newNums=newint[size];
Random numGen=new Random();//这将用于生成随机数
for(int-elementNum=0;elementNum
您可能希望查看System.Random类。考虑如何在CyTrAtAdOnMyLimFrimeLabar函数中的循环中使用它来设置数组中的值。另外,Printarray函数并没有做您认为不需要的事情。考虑将数组索引作为参数写入到您的WrimeLead(控制台.WrreLead(“{ 0 }”,Value[i])中,谢谢,我根据您的理解进行了编辑!返回时仍有错误。非常感谢!我会更仔细地阅读你的建议。我必须像程序员一样思考,因为我不擅长思考。
class Program
{
    /*
    I assume you are trying to
    1. Create an array of integers
    2. Store random numbers (between 0 and 100) inside that array
    3. Print the numbers in the array 

    You have alot of reading to do as theres alot of fundemental mistakes in both your approach and code.
     */
    static void Main(string[] args)
    {

        // creating an array with random numbers
    ArrayMethods m = new ArrayMethods();
    int[] nums1; 
    nums1 = m.CreateRandomlyFilledArray(10);          

    m.Printarray(nums1);

    }

    class ArrayMethods
    {
        /*
             - First you have to fill the array with random numbers
        In your solution, you have created "CreateRandomlyFilledArray".
         1. You created the a new array of integers which is good
         2. The way you attempted to fill the new array is incorrect
        */
        public int[] CreateRandomlyFilledArray(int size)
        {
            int[] newNums = new int[size];

            Random numGen = new Random(); //  This will be used to generate random numbers
            for (int elementNum = 0; elementNum < newNums.Length; elementNum++)
            {
                // here we will put a random number in every position of the array using the random number generator
                newNums[elementNum] = numGen.Next(0, 100); // we pass in you minimum and maximum into the next function and it will return a random number between them
            }

            // here we will return the array with the random numbers
            return newNums;
        }

        /*
        - This function prints out each item in an integer array
            1. You do not need to a return value as you will not be returning any thing so, Use "void".
        */
        public void Printarray(int[] value)
        {
            for (int i = 0; i < value.Length; i++)
            {
                Console.WriteLine("value is: {0}", value[i]);
            }
        }

    }
}