日期:2014-05-17 浏览次数:20672 次
string[,] csys_a = new string[,] { { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }, { "白", "灰", "黄", "粉", "红", "紫", "绿", "蓝", "棕", "黑" } };
label.Text = "J" //这里的的J替换为相应的颜色。
void Main()
{
string[] ay1={ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" };
string[] ay2={ "白", "灰", "黄", "粉", "红", "紫", "绿", "蓝", "棕", "黑" } ;
string key="J";
string result=(from a in ay1.Select((x,y)=>new {x,y})
join b in ay2.Select((x,y)=>new {x,y})
on a.y equals b.y
where a.x==key
select b.x).FirstOrDefault();
if(result !=null)
Console.WriteLine(result); //黑
else
Console.WriteLine("No result found!");
}
------解决方案--------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
string[,] csys_a = new string[,] { { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }, { "白", "灰", "黄", "粉", "红", "紫", "绿", "蓝", "棕", "黑" } };
public Form1()
{
InitializeComponent();
}
//字母返回颜色,没有返回空
public string Switch(string Astr)
{
int k = csys_a.GetLength(1);
for (int i = 0; i < k ; i++)
{
if (csys_a[0, i] == Astr)
{
return csys_a[1, i];
}
}
return "";
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = "F";
label1 .Text =Switch (label1 .Text );
}
}
}
这应该满足lz的要求