数组取值问题 string[,] csys_a = new string[,] { { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }, { "白", "灰", "黄", "粉", "红", "紫", "绿", "蓝", "棕", "黑" } };求助:我有这么个数组,如何根据 "A", "B", "C", "D", "E等得到后面的颜色如label.Text = "J" //这里的的J替换为相应的颜色。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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!");} 擦,,想的复杂了,直接一句话就可以: Console.WriteLine(ay2[Array.IndexOf(ay1,key)]); 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的要求 .NET下如何实现伪静态,服务器不在本地能实现吗? vs08sp1问题 有使用过ASP.NET 2.0 提供程序模型的来介绍介绍,说说看法???? v2008安装错误 web.mail 批量发送邮件 急救!未知的撤消/重复 菜鸟问:什么是web service flash,非常急,谁会帮帮忙 关于公共字符串常量的问题 如何在ASP.net中用vb.net修改域帳戶的密碼,謝謝 Request["name名字"] 获取不到 ASP.NET 发送邮件 怎么带格式?
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!");
}
Console.WriteLine(ay2[Array.IndexOf(ay1,key)]);
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的要求