c#的几个问题
- 提问者网友:相思似海深
- 2021-07-30 22:34
- 五星知识达人网友:鱼芗
- 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());
}
}