대규모 클래스를 작성,이 코드를했는데, 그것은 바로는 C#
using System;
namespace Massiv1
{
class Program
{
static void Main(string[] args)
{
Console.Write("n = ");
int n = Convert.ToInt32(Console.ReadLine());
Massiv mas = new Massiv(n);
mas.ShowAll();
Console.Write("i = ");
int i = Convert.ToInt32(Console.ReadLine());
mas.ShowElement(i);
Console.ReadLine();
}
}
class Massiv
{
public Massiv(int n)
{
int[] mas = new int[n];
Random rand = new Random();
for (int i = 0; i < mas.Length; ++i)
{
mas[i] = rand.Next(0, 10);
}
}
public void ShowAll()
{
foreach (var elem in mas)
{
Console.Write(elem + " ");
}
Console.WriteLine();
}
public void ShowElement(int index)
{
try
{
Console.WriteLine("index {0} mas{1} = ", index, mas[index]);
}
catch (NullReferenceException)
{
Console.WriteLine("Error!");
}
}
public int this[int index]
{
get { return mas[index]; }
set { mas[index] = value; }
}
private int[] mas;
}
}
내 방법 ShowAll 관련이 작동하지 않는 일 does'n 나는 이유를 이해 해달라고. 그것을 고치는 방법?
그것이 작동하지 않는다는 것이 무엇을 의미합니까? 당신이 원하는 것을 인쇄하지 않습니까? 그것은 당신에게 오류를 제공합니까? – SOfanatic
자세한 내용을 알려 주셔야합니다. 이 코드로 무엇을하려고합니까? ShowAll은 어떻게 작동하지 않습니까? 오류? 잘못된 출력입니까? – Tim