我有一組名爲像這樣的對象:如何投放字符串爲int
_1,_2,_3 .... _n
不是數組,只是一堆uinto自定義控件對象。我想把這個名字轉換爲int。首先我刪除_
,但如果使用
private void Superficie_MouseDown(object sender, MouseButtonEventArgs e)
{
int index = 0;
Shape myShape = ((Shape)sender);
string lcNombre = myShape.Name.Remove(0, 1);
//--------------------------------------------------------------------
// Those are my tryes
// Doesn't work because it must expect a nullable value
index = lcNombre as decimal;
// Doesn't work Can't convert string to int
index = (int)lcNombre;
//--------------------------------------------------------------------
if (index > 0)
{
bool lIsSelected = !Pieza.Superficies.Where(x=>x.Id == index).First().IsSelected;
Pieza.Superficies.Where(x => x.Id == index).First().IsSelected = lIsSelected;
if (lIsSelected)
myShape.Fill = new SolidColorBrush(SystemColors.HotTrackColor);
else
myShape.Fill = new SolidColorBrush(SystemColors.ControlLightLightColor);
}
}
我該怎麼做才能施放它?
我必須失去它。時間去睡覺;-) – Harrison