Hi, sorry for the newbie question but, I'm new to programming..
I want to check if there's already no more than one element of TypeA
in listOfDifferentTypes
. I've following code:
public void CheckType ( Object param)
{
if ( param is TypeA )
{
int i = 0;
TypeA paramToCheck = ( TypeA ) param;
foreach ( var paramB in listOfDifferentTypes )
{
if ( paramB is TypeA )
{
var paramInList = ( TypeA ) paramB;
if ( paramToCheck.ID == paramInList.ID )
{
i++;
}
}
}
if ( i > 1 )
{
paramToCheck.m_Error = "ErrorText";
}
}
}
I consider it's not very clean solution. Can this code be improved / optimized?