永发信息网

c#的几个问题

答案:1  悬赏:50  手机版
解决时间 2021-07-31 16:37
  • 提问者网友:相思似海深
  • 2021-07-30 22:34
c#的几个问题
最佳答案
  • 五星知识达人网友:鱼芗
  • 2021-07-30 23:46

第一题:


using System;
using System.Collections.Generic;
using System.Text;


namespace Test
{
class Program
{
static void Main(string[] args)
{


List<Student> stu = new List<Student>(10);
StuInfo si = new StuInfo(ref stu);
si.AddStu(tname,tsex,tage);
si.findStuByIndex(0);
Console.ReadLine();


}


}


public struct Student
{
public Student(ref string name,ref string sex,ref int age)
{
this._name = name;
this._sex = sex;
this._age = age;
}
private string _name;


public string Name
{
get { return _name; }
set { _name = value; }
}
private string _sex;


public string Sex
{
get { return _sex; }
set { _sex = value; }
}
private int _age;


public int Age
{
get { return _age; }
set { _age = value; }
}
public string GetInfo()
{
return string.Format("姓名:{0};性别:{1};年龄:{2}",this._name,this._sex,this._age);
}
}
public struct StuInfo
{
public StuInfo(ref List<Student> stu)
{
this._stu = stu;
}
private List<Student> _stu;
public List<Student> Stu
{
get { return _stu; }
set { _stu = value; }
}
public void AddStu(string name,string sex,int age)
{
Student stu=new Student();
stu.Name = name;
stu.Sex = sex;
stu.Age = age;
this._stu.Add(stu);
Console.WriteLine("添加信息成功");
}
public void findStuByIndex(int index)
{
Console.WriteLine("学员{0}的信息是{1}:",index+1,this._stu[index].GetInfo());
}
}


我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯