In: Computer Science
Below is my code in C#,
When I run it, the output shows System.32[], Can you please check and let me know what is the problem in the code.
class Program
{
static void Main(string[] args)
{
int number=12;
Console.WriteLine(FizzArray(number));
}
public static int[] FizzArray(int number)
{
int[] array = new int[number];
for (int i = 1; i < number; i++)
array[i] = i;
return array;
}
Code:
using System;
class Program
{
static void Main(string[] args)
{
// declare a variable number = 12
int number=12;
// let us create an array
//this array strores the returned array from FizzArray
functoin
int[] array = FizzArray(number);
// we need to iterate through the array to print the
elements
//if we directly print we will get output like System.32[]
//iterate for every item in array
foreach (var item in array)
{
// print in the Console
Console.WriteLine(item);
}
}
// method that returns an array
public static int[] FizzArray(int number)
{
// create an array of size number
int[] array = new int[number];
// usign for loop assign the values to the array
for (int i = 1; i < number; i++)
// assign values to array
array[i] = i;
// return the array
return array;
}
}