I want to add Object as many type. I have search for this particular problem but I can't find any help on this scenario. Suppose I have a button click event that have many types, which are define below
object[] InvokeParam = null;
private void btnCall_Click(object sender, EventArgs e)
{
string t = "";
int t1 = 0;
float t2 = 0.2;
InvokeParam = new object[3];
string type = RecognizeType(t.GetType(),0);
string type1 = RecognizeType(t1.GetType(), 1);
string type2 = RecognizeType(t2.GetType(), 2);
}
and RecognizeType function is
private string RecognizeType(Type type,int Index)
{
string typename = "";
if (type.Equals(typeof(string)))
{
//InvokeParam[Index] = type as string;
typename = "String";
}
else if (type.Equals(typeof(int)))
{
typename = "Int";
}
else if (type.Equals(typeof(double)))
{
typename = "Double";
}
else if (type.Equals(typeof(Single)))
{
typename = "Single";
}
else if (type.Equals(typeof(float)))
{
typename = "Float";
}
else if (type.Equals(typeof(decimal)))
{
typename = "Decimal";
}
else
{
typename = "Another Type";
}
return typename;
}
I want every object in array as particular Type. If 1st one is of type string then it can make that index of object as string, so whenever any value enter by user it throws exception when another value other than string is entered.
Aucun commentaire:
Enregistrer un commentaire