2014-04-21 40 views
-1

我已經創建了一個包含很多選項的列表,讓我們假設每個字符具有不同的顏色。從列表中分配字符串

string A = "#FFB97FC9"; 
string B = "#FF9BCC50"; 
// etc. 
string answer1 = Options.Answer1; 
answerRectangle.Fill = GetColorFromHexa(answer1); 

現在讓我們說,Options.Answer1 = A

我想answerRectangle有從代碼#FFB97FC9

顏色我怎樣才能做到這一點?

注:我想有answer1 = #FFB97FC9

+2

列表在哪裏 –

+0

請說明一下。 –

+0

-1標題應該是「從十六進制值指定顏色」 – ja72

回答

1

爲什麼不創建一個字典,選擇:

Dcitionary<string, string> colors = new Dictionary<string, string>(); 
colors.Add("A", "#FFB97FC9"); 
colors.Add("B", "#FF9BCC50"); 

,然後:

answerRectangle.Fill = GetColorFromHexa(colors[answer1]); 
2

使用字典而不是變量:

var colors = new Dictionary<string, string>(); 
colors["A"] = "#FFB97FC9"; 
colors["B"] = "#FF9BCC50"; 
// etc. 
string answer1 = Options.Answer1; 
answerRectangle.Fill = GetColorFromHexa(colors[answer1]);