- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Bear
- {
- class 手机
- {
- public string 品牌 { get; set;}
- public string 型号 { get; set; }
- public string 颜色 { get; set; }
- public float 价格 { get; set; }
- public void 录入手机信息()
- {
- Console.WriteLine("请输入手机的品牌 :");
- this.品牌 = Console.ReadLine();
- Console.WriteLine("请输入手机的型号 :");
- this.型号 = Console.ReadLine();
- Console.WriteLine("请输入手机的颜色 :");
- this.颜色 = Console.ReadLine();
- Console.WriteLine("请输入手机的价格 :");
- this.价格 = float.Parse(Console.ReadLine());
- }
- public void 显示手机信息()
- {
- Console.WriteLine("品牌 :" + this.品牌);
- Console.WriteLine("型号 :" + this.型号);
- Console.WriteLine("颜色 :" + this.颜色);
- Console.WriteLine("价格 :" + this.价格);
- }
- }
- class 调用
- {
- static void Main(string[] args)
- {
- 手机[] phone=new 手机[3];
- for (int i = 0; i < phone.Length;i++ )
- {
- 手机 p = new 手机();
- p.录入手机信息();
- }
- float max=phone[0].价格;
- int 位置 = -1;
- for(int i=0;i<phone[i].价格;i++)
- {
- if(max<phone[i].价格)
- {
- max = phone[i].价格;
- 位置 = i;
- }
- }
- phone[位置].显示手机信息();
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/2406201512912.html
来源: http://www.codesnippet.cn/detail/2406201512912.html