关于c#中两个不同类型数组排序问题?!

来源:百度知道 编辑:UC知道 时间:2024/06/20 09:52:52
一、循环输入,电脑配件cpu、内存、硬盘、显卡、光驱、主机、显示器的价格,并按配件名称的价格高低进行排序,并输出配件总价格。
(以下是我做的,但是只能实现价格的排序,无法解决按配件名称的价格高低进行排序,请哪为高手讲解以下,感激不尽,在线等待中...)

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

namespace L24
{
class Program
{
static void Main(string[] args)
{
int temp;
int sum = 0;
int j, h;
int[] price = new int[7];
string[] a = new string[7] { "cpu", "内存", "硬盘", "显示", "光驱", "主机", "显示器" };

for (h = 0; h < 7; h++)
{
Console.WriteLine("请输入{0}的价格:", a[h]);
price[h] = int.Parse(Console.ReadLine());
sum = sum + price[h];

}

for (int i = 0; i < price.Length - 1; i++)
{

string tempStr="";
for (int i = 0; i < price.Length - 1; i++)
{
for (j = 0; j < pr.3ice.Length - 1 - i; j++)
{
if (price[j] > price[j + 1])
{
temp = price[j];
tempSt = a[j];
price[j] = price[j + 1];
a[j] =a[j + 1];
price[j + 1] = temp;
a[j+1]=tempStr;
}
}
}

你这个这能录入一条信息,
建议写个类
class Computer
{
private float cupPrice;//cpu价格
public float CupPrice
{
get {return cupPrice;}
set {cupPrice = value;}
}
private float memoryPrice;//内存价格
.....
.....
}

Computer[] myPC = new Computer[50];//new 一个Computer数组,记录一条信息
myPC[0].CpuPrice = "cup的价格";
myPC[0].MemoryPrice = "内存价格";
这样可以记录多条电脑信息.