C#类与数组————在其他的类如何调用main函数的数组问题
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication8
{
public class Student
{
private string name;
private int chengji;
public string Name
{
get { return name; }
set { name = value; }
}
public int Chengji
{
get { return chengji ; }
set { chengji = value; }
}
public void cahxun()//通过输入学生姓名查找其成绩的方法
{
string s = Console.ReadLine();
for (int i = 0; i < 35; i++)
{
if (s == s[i])//通过姓名数组的下标找到他的五门成绩
{
for (int j = 0; j < 5; j++)
{
Console.WriteLine(stu[i, j]);
}
}
}
}
}
class Program
{
static void Main(string[] args)
{
Student[] s = new Student[35];
for (int i = 0; i < 35; i++)//记录姓名
{
s[i] = new Student();
s[i].Name = Console.ReadLine();
}
Student [,] stu = new Student[35, 5];
for (int n = 0; n < 35; n++)//记录35名学生的五门成绩
{
for (int m = 0; m < 5; m++)
{
stu[n,m]=new Student ();
stu[n, m].Chengji = int.Parse(Console.ReadLine());
}
}
}
}
}