试试这个:
var foo = str.Split(' '); //from 111 Simon will get '111'
var id = foo.Length > 1 ? foo[0] : null;
if(id != null) {
//do something with '111';
} else {
//error
}
编辑
我建议你做通过使用自定义Combobox
类:
public class Foo
{
public string Text { get; set; }
public int Value { get; set; }
public Foo(int id, string name)
{
Value = id;
Text = name;
}
public override string ToString()
{
return Text;
}
}
然后添加object
(富)为combobox
:
comboBox1.Items.Add(new Foo(111, "simon"));
然后你就可以通过铸造SelectedItem
属性类访问值:所选择的响应
//assuming that comboBox1.SelectedText is "simon", the following is true:
var val = (Foo)comboBox1.SelectedItem;
val.Value // 111
val.Text // simon
'comboBox1.SelectedText.Split('')' – 2012-07-16 15:01:34
这会返回什么? mySplit [0] = 111和mySplit [1] = Simon? – phadaphunk 2012-07-16 15:02:49
是的,它会........... – 2012-07-16 15:04:09