/// <summary> /// 电脑类 /// </summary> public class Computer { public string Type { get; set; } }
/// <summary> /// /// </summary> /// <param name="computers">用户传入的待加工的数据</param> /// <returns>加工后的结果数据</returns> public Computer[] Func(Computer[] computers) { //苹果 +小苹果 //联想 +++小联想 //惠普 小惠普 //结论:数组有两种遍历方式,有一种就是foreach /* foreach (Computer computer in computers) { //数组中的一台电脑对象 computer.Type="小"+computer.Type; } //12分钟 return computers; }
static void Main(string[] args) { //ToolA toolA=new ToolA(); //toolA.Func("张靓颖"); //ToolB b=new ToolB(); //string result=b.Func("微冷的雨训练营"); //Console.WriteLine(result); ToolC c=new ToolC(); Computer[] comps=new Computer[3]; comps[0]=new Computer(); comps[0].Type = "苹果"; comps[1] = new Computer(); comps[1].Type = "联想"; comps[2] = new Computer(); comps[2].Type = "惠普"; Computer[] compsnew = c.Func(comps); foreach (Computer computer in compsnew) { Console.WriteLine(computer.Type); } Console.ReadKey();