| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2208 人关注过本帖
标题:C#类与数组————在其他的类如何调用main函数的数组问题
只看楼主 加入收藏
冷锋2048
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2015-10-27
结帖率:57.14%
收藏
已结贴  问题点数:20 回复次数:1 
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());
                }
            }
        }
    }
}
搜索更多相关主题的帖子: private public return 如何 
2016-04-21 12:51
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:20 
程序代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleTest
{
    class Student
    {
        public string name;
        public int[] score;

        public Student()
        {
            this.name = string.Empty;
            this.score = new int[5];

            for(int i=0;i<5;i++)
            {
                this.score[i] = 0;
            }
        }

        public void display()
        {
            Console.WriteLine("{0}:{1},{2},{3},{4},{5}", name, score[0], score[1], score[2], score[3], score[4]);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Student[] s = new Student[5];
            for (int i = 0; i < 5; i++)//记录姓名
            {
                s[i] = new Student();
                s[i].name = Console.ReadLine();
            }

            for (int n = 0; n < 5; n++)//记录35名学生的五门成绩
            {
                for (int m = 0; m < 5; m++)
                {
                    s[n].score[m] = int.Parse(Console.ReadLine());
                }
            }

            for(int i=0;i<5;i++)
            {
                s[i].display();
            }
            Console.ReadKey();
        }
    }
}

   唯实惟新 至诚致志
2016-04-21 19:10
快速回复:C#类与数组————在其他的类如何调用main函数的数组问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024347 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved