I have an arraylist that gets different types of values , the first value is → string , the second value is → datetime , 3rd value is → boolean , and the fourth value is int , how can I find its type and assign these values accordingly, any help would be appreciated :)
here is my code:
foreach (object obj in lstTop)
{
if(obj.GetType() == string)
{do this...)
else if(obj.GetType() == DateTime)
{do this....}
else if(obj.GetType() == bool)
{do this....}
else if(obj.GetType() == Int)
{do this....}
}
Thanks to everyone, my final code is:
string Subscription = "";
DateTime issueFirst;
DateTime issueEnd;
foreach (object obj in lstTop)
{
if (obj is string)
Subscription += obj + ",";
else if (obj is DateTime)
{
Subscription += Convert.ToDateTime(obj).ToShortDateString() + ",";
}
}
return ("User Authenticated user name: " + userName + ", Subscription: " + Subscription);
source
share