This part of code is responsible to capture user input from keyboard and use it. When i press some button (ex. C) on keyboard variable TAG receives this as object (byte) value 3. i cannot find out why debugger returns the following error: System.InvalidCastException. Specified cast is not valid. num and tag declared as integer value. what is wrong? In this line int? tag = (int?) this.pnlAnswers.Controls[num.Value].Tag; - debugger points to .Tag at the end of line as error.
private void Question_KeyDown(object sender, KeyEventArgs e)
{
int? num = null;
this.qta.get_answer_number_by_key(new int?(e.KeyValue), ref num);
if (!num.HasValue)
{
this.SwitchQuestion(e.KeyValue);
}
else
{
num -= 1;
bool? nullable2 = false;
bool? end = false;
if (this.pnlAnswers.Controls.Count >= (num + 1))
{
Valid valid;
int? tag = (int?) this.pnlAnswers.Controls[num.Value].Tag;
this.qta.test_answer(this.q, tag, ref nullable2, ref end, ref this.pass);
this.e = end.Value;
if (nullable2.Value)
{
valid = new Valid(MessageType.Valid);
}
else
{
valid = new Valid(MessageType.Invalid);
}
valid.ShowDialog();
base.Close();
}
}
}
i`ve tried to change
int? tag = (int?) this.pnlAnswers.Controls[num.Value].Tag;
to
byte? tag = (byte?) this.pnlAnswers.Controls[num.Value].Tag;
and error gone, however i have issues with post-processing of receiving this values.
int?
and not toint
, if it's an integer? – Tomas Pastircakt know, i
ve used references and im not experienced developer, sorry. that
s why i need help. – Gambarskyint
only? :) – Tomas Pastircak